Login Register






How to ping an IP with PHP filter_list
Author
Message
How to ping an IP with PHP #1
Well not sure if this is at all useful to anyone here but you can ping an IP via PHP and it's all pretty simple really. Just a small portion of code and it's done. You can adjust this so it sends multiple pings but I won't post that version unless people actually find this one interesting.

So here we go.

Code:
<?php $ip =   "127.0.0.1"; exec("ping -n 3 $ip", $output, $status); print_r($output); ?>

The output of the above PHP code is like shown below.
output looks like below
Code:
Array (    [0] =>    [1] => Pinging 127.0.0.1 with 32 bytes of data:    [2] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128    [3] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128    [4] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128    [5] =>    [6] => Ping statistics for 127.0.0.1:    [7] =>     Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),    [8] => Approximate round trip times in milli-seconds:    [9] =>     Minimum = 0ms, Maximum = 0ms, Average = 0ms )

Reply

RE: How to ping an IP with PHP #2
Isn't it better to just ping from the terminal then?

Reply

RE: How to ping an IP with PHP #3
Isn't it possible to just do

Code:
<?php exec("ping -n 3 127.0.0.1", $output, $status); print_r($output); ?>
I'll probably hate you if you're retarded..

Reply

RE: How to ping an IP with PHP #4
This is gonna ping forever on a linux host though, if it even recognizes the command.

Reply

RE: How to ping an IP with PHP #5
This not always possible, since 99% of shared hosts don't allow this.

Reply

RE: How to ping an IP with PHP #6
why would you want to forever ping? to dos? ping wont do a dam thing.

Windows (CMD Prompt)

This works in Win95, Win98, WinXP, Win7, Win8 etc. Go to start, then run, type in cmd to open a command prompt.

Code:
ping 192.168.1.1 -t


Unix/Linux Shell

In *nix it is continuous by default.

Code:
ping 192.168.1.1

You can also indicate a high count which will ping for a very long time. This example will ping something 9,999,999 times.

Code:
ping 192.168.1.1 -c 9999999

If you are in linux and it is not doing a continuous ping by default there is probably an alias for the ping command which is changing the way you envoke ping. Find where the ping command is using which ping then call the program from there and it should be continuous.

Code:
/bin/ping 192.168.1.1


Mac and OSX

In OSX it is continuous by default.

Code:
ping 192.168.1.1

If that doesn’t work you can get it to be continuous by doing this command instead:

Code:
/sbin/ping 192.168.1.1


Cisco Router/Firewall/Switch


You cannot do a continuous ping from a Cisco router, firewall or switch. This includes ASA and IOS operating systems. You can however do a ping for a VERY long time by indicating a lot of pings.

Code:
ping 192.168.1.1 repeat 9999999

Or if the repeat command is unavailable use the extended ping by simply issuing the ping command by itself and follow the prompts after.

If that still isn’t good enough, you can set up an SLA monitor to actually ping forever.


Juniper JunOS


In JunOS it is continuous by default.

Code:
ping 192.168.1.1


Stopping a ping

On any of the systems above you can halt the ping.

To stop the continuous ping press CONTROL+c.

Tongue
You mind is programmable – if you’re not programming your mind, someone else will program it for you.

Reply

RE: How to ping an IP with PHP #7
I would've named this tutorial "How to Execute Commands w/ PHP". It would've been more useful to tell people that don't see the obvious that exec() runs any native command. Smile

Reply

RE: How to ping an IP with PHP #8
More commonly known as "How to get yourself owned by an RCE"

Reply

RE: How to ping an IP with PHP #9
Anyone else seeing this?

Code:
$ip = "127.0.0.1";

Code:
exec("ping -n 3 $ip", $output, $status);

Anyone see that? Yeah, great.

Reply

RE: How to ping an IP with PHP #10
You must be very careful when using exec() especially when accepting user parameters.

Also this will expose your web server IP to the pinged server leaving you open for DDoS attacks.

Here is what I recommend, it's simple, effective, and safe.

<?php

$IP = $_GET['IP'];

$result = file_get_contents("http://APIOnly.com/pingipv4.php?ip={$IP}");

echo $result;

?>

Reply