Ping Question

Discussion in 'Mac Programming' started by bobber205, Aug 26, 2006.

  1. macrumors 68020

    bobber205

    Joined:
    Nov 15, 2005
    Location:
    Oregon
    #1
    Whenever I ping an address through PHP (the exec command) and when it's hte second time or more since I've done the same command, I get something like this.
    Code:
    round-trip min/avg/max/stddev = 3.917/3.917/3.917/0.000 ms 
    Which is NOT what I want. Any suggestions?

    or comments. There must be something I'm missing.

    EDIT:
    Ooh! It's not just giving me the above line, but instead exec is giving back just the last line.

    Code:
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 79.492/80.872/82.678/1.335 ms
    
    Any idea on how to stop this?
     
  2. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    That looks like what you get in Terminal...

    Code:
    Last login: Sun Aug 27 11:56:05 on ttyp1
    Welcome to Darwin!
    Vigor14:~ Matthew$ ping -c 2 192.168.1.1
    PING 192.168.1.1 (192.168.1.1): 56 data bytes
    64 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=0.592 ms
    64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.646 ms
    
    --- 192.168.1.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 0.592/0.619/0.646/0.027 ms
    Vigor14:~ Matthew$ ping -c 2 192.168.1.1
    PING 192.168.1.1 (192.168.1.1): 56 data bytes
    64 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=0.644 ms
    64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.534 ms
    
    --- 192.168.1.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 0.534/0.589/0.644/0.055 ms
    Vigor14:~ Matthew$ 
    
    The -c 2 limit's it to sending 2 pings
     
  3. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #3
    What do you want??
    grep, sed, preg_replace()...hard to say since I don't understand what your actual goal is here.
     
  4. thread starter macrumors 68020

    bobber205

    Joined:
    Nov 15, 2005
    Location:
    Oregon
    #4
    sorry.

    What I actually want it is all the text from the exec command being able to be stored in a variable.
     
  5. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #5
    Oh. Can you post the exact code that you're trying to use? Also, try using system() instead of exec(). This works on a server that I'm using at the moment:

    Code:
    [atmeweb@boxwood bin]$ cat test.php
    <?php
    echo(system("nslookup google.com"));
    ?>
    
    [atmeweb@boxwood bin]$ php-cli test.php
    Server:         64.29.16.113
    Address:        64.29.16.113#53
    
    Non-authoritative answer:
    Name:   google.com
    Address: 72.14.207.99
    Name:   google.com
    Address: 64.233.167.99
    Name:   google.com
    Address: 64.233.187.99
    
    You can also pass an array into exec to get lines of output stored in an array.
    http://us2.php.net/function.exec
     

Share This Page