pinging from within python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M.N.A.Smadi

    #1

    pinging from within python

    hi;

    I need a simple script to run the ping command with some parameters and
    be able to read the return value of the ping function. Any pointers will
    be appreciated

    thanks
    m.smadi
  • Grant Edwards

    #2
    Re: pinging from within python

    On 2005-09-11, M.N.A.Smadi <smadim2@grads. ece.mcmaster.ca > wrote:
    [color=blue]
    > I need a simple script to run the ping command with some parameters and
    > be able to read the return value of the ping function. Any pointers will
    > be appreciated[/color]



    --
    Grant Edwards grante Yow! I think my CAREER
    at is RUINED!!
    visi.com

    Comment

    • billiejoex

      #3
      Re: pinging from within python

      Impacket module can helps you to construct the ip/icmp packet structure,
      then you can send the packet and wait for the ECHOREPLY by using a
      RAW_SOCKET.
      Here's an example:
      http://oss.coresecurity.com/impacket/ping.py

      Cheers
      [color=blue]
      > I need a simple script to run the ping command with some parameters and be
      > able to read the return value of the ping function. Any pointers will be
      > appreciated
      >
      > thanks
      > m.smadi[/color]


      Comment

      • Jorgen Grahn

        #4
        Re: pinging from within python

        On Mon, 12 Sep 2005 01:36:35 +0200, billiejoex <billiejoex@fas twebnet.it> wrote:[color=blue]
        > Impacket module can helps you to construct the ip/icmp packet structure,
        > then you can send the packet and wait for the ECHOREPLY by using a
        > RAW_SOCKET.
        > Here's an example:
        > http://oss.coresecurity.com/impacket/ping.py[/color]

        Yeah, but is he willing to be root, and ditch Windows, just to be able to
        ping? Exec()ing the ping utility is often better, but beware -- different
        pings take different options.

        [the original poster][color=blue][color=green]
        >> I need a simple script to run the ping command with some parameters and be
        >> able to read the return value of the ping function.[/color][/color]

        What is "the return value of the ping function"? You can use the ping
        utility for many different things, and it reports many different kinds of
        outcomes. It's not black and white.

        /Jorgen

        --
        // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
        \X/ algonet.se> R'lyeh wgah'nagl fhtagn!

        Comment

        • Harlin Seritt

          #5
          Re: pinging from within python

          You can do the following:

          import os

          data = os.popen('ping machineName').r ead()
          if 'request timed out' in data or 'unknown host' in data:
          Ping Failed Code
          else:
          Ping Returned Something Good Code

          This is the quickest and really most effective way to get it done IMO.

          Harlin Seritt
          Internet Villa: www.seritt.org

          Comment

          Working...