Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Can I know, using PHP (and ping, i think), if a ip is online in the internet?
Is there a script for it?
Thx


The answer is yes and no. If you can't ping an IP it doesn't necessarily mean there is no device at that IP. Pinging can be blocked under certain circumstances - usually for security reasons.
Also, your terminology is a little incorrect which is confusing the issue (which is the reason for the previous respondent's questions). An IP is not online - a device can be on a network and will have an IP when it does. That IP can be public (internet) or private (internal LAN).
So, assuming there is a computer at a specific IP that you know you can ping, then the answer to your question is yes. Here is one solution: PHP Ping
Michael J

Define "automatically". Are you wanting to ping based upon a certain event or trigger. Or, are you wanting to have a ping based on a specified time interval?
If it is based upon an even, it will depend upon the event as to whether it can be done and how. If it is based upon time you could set up a scheduled task on the server.
Why don't you just tell us what it is you are trying to accomplish. There could be a very simple solution.
Michael J

Sorry... my english is very bad :(
eheheI want some like this:
$x = ping("123.123.123.123");
if ($x) echo "the ip is connected";

Yeah, it can be done. I suggest you write your own script since everything out there seems to suck (post it on planetsourcecode for the rest of us).
I'm building a similar app at work right now, sorry can't share the code. I can point you in a good direction though.
Using PHP you can execute shell commands in a variety of ways such as (`ping 127.0.0.1` - backticks, eval(), escape(), and more).
The response you retrieve will will be specific to the ping application for the machine you are using.
You can do a $response = `ping 127.0.0.1 -c 1`; - or a similar command to suck in the response. From there you can parse the hell out of the input to get what you want (msecs, packet loss, etc).
Hint: Unknown hosts usually give you no response (On all OS's I have tried) - which is ok since everything else does. Three types of hosts (Unknown, Reachable, Unreachable). You will get a response time with reachable hosts and no response time with unreachable (Assuming your only going to ping it once at a given interval).

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |