/    Sign up×
Community /Pin to ProfileBookmark

Detecting PCs on Network with PHP

Is there anyway that a PC can be tested by a PHP script to see if it is on the network (switched on) and then display a customisable message to say if it is on or off?

Many Thanks
Paul

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderApr 12.2007 — If you know the IP address of the machines you could just ping them?
Copy linkTweet thisAlerts:
@usikApr 12.2007 — well it depends, is this a local php script? or are these computers networked to the server? you have left many blanks
Copy linkTweet thisAlerts:
@paul_harrisauthorApr 13.2007 — I have the PCs networked via a router to a PC (acting as a server) with IIS on it. You mentioned pinging the PCs. What script can I use to do this and get the script to say a customisable message such as "Computer x is online"?

Many Thanks

Paul
Copy linkTweet thisAlerts:
@bathurst_guyApr 13.2007 — Here's a quick and nasty[code=php]<?php
$os = "mac"; // What OS will this PING be running on? win = Windows, mac = Macintosh/Linux
$ips = array( // Set all your IP addresses here and a name
"192.168.1.1" => "Gateway",
"192.168.1.2" => "Webserver",
"192.168.1.3" => "Another"
);

// You dont need to edit below here

$count = ""; //disinfect
$ip = "";

if($os == "win"){
$count = "-n 1"; // sets to ping only once (because otherwise this script can take a while!)
$ereg = "Lost = 0";
}else{
$count = "-c1"; // sets to ping only once (because otherwise this script can take a while!)
$ereg = "0% packet loss";
}
echo "<pre>";
foreach($ips as $ip => $name){
$result = ping $count $ip; // run PING
$test = ereg($ereg,$result); // Check results
echo "Computer "$name" ($ip) is ";
if($test == TRUE){ // if 0% packet loss
echo "alive<br>"; // YEY!
}else{ // otherwise
echo "dead<br>"; // BOO!
}
}
echo "</pre>";
?>
[/code]
Copy linkTweet thisAlerts:
@paul_harrisauthorApr 14.2007 — Thanks for the script bathurst_guy. I tried running it and changed os to Windows and put in ips but all i get is "PHP Warning: shell_exec() [function.shell-exec]: Unable to execute 'ping -n 1 192.168.0.102' in C:Inetpubwwwrootimagesping.php on line 23". Anyone got any ideas? I haven't changed anything other than the os and the ips.

Thanks

Paul
Copy linkTweet thisAlerts:
@bathurst_guyApr 15.2007 — The option shell_exec has to be removed from the line disable functions in the php configuration file /etc/php.ini

Just open the php.ini file and search or shell_exec then comment it out with a #, save and reboot apache.
Copy linkTweet thisAlerts:
@paul_harrisauthorApr 15.2007 — Thanks for the reply. I just opened the php.ini file and used the find function to search for shell_exec. I cannot find this anywhere in the php.ini file. Do I have an old version of PHP? It is installed on a PC using IIS server for an intranet.

Thanks

Paul
×

Success!

Help @paul_harris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...