![]() |
|
How to ping an IP with PHP - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: PHP (https://sinister.li/Forum-PHP) +--- Thread: How to ping an IP with PHP (/Thread-How-to-ping-an-IP-with-PHP) Pages:
1
2
|
How to ping an IP with PHP - Dreamzje - 08-10-2015 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
)RE: How to ping an IP with PHP - Oxyrus - 08-11-2015 Isn't it better to just ping from the terminal then? RE: How to ping an IP with PHP - Kevin_SF - 08-11-2015 Isn't it possible to just do Code: <?php
exec("ping -n 3 127.0.0.1", $output, $status);
print_r($output);
?>RE: How to ping an IP with PHP - Dutch - 08-11-2015 This is gonna ping forever on a linux host though, if it even recognizes the command. RE: How to ping an IP with PHP - Kill - 08-11-2015 This not always possible, since 99% of shared hosts don't allow this. RE: How to ping an IP with PHP - Captin_Lulzboat - 08-11-2015 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 -tUnix/Linux Shell In *nix it is continuous by default. Code: ping 192.168.1.1You 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 9999999If 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.1Mac and OSX In OSX it is continuous by default. Code: ping 192.168.1.1If that doesn’t work you can get it to be continuous by doing this command instead: Code: /sbin/ping 192.168.1.1Cisco 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 9999999Or 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.1Stopping a ping On any of the systems above you can halt the ping. To stop the continuous ping press CONTROL+c.
RE: How to ping an IP with PHP - Dijkstra - 09-05-2015 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.
RE: How to ping an IP with PHP - Meowie - 09-18-2015 More commonly known as "How to get yourself owned by an RCE" RE: How to ping an IP with PHP - Sky_mybb_import16331 - 09-24-2015 Anyone else seeing this? Code: $ip = "127.0.0.1";Code: exec("ping -n 3 $ip", $output, $status);Anyone see that? Yeah, great. RE: How to ping an IP with PHP - Nick Lim - 10-18-2015 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; ?> |