plznty Posted August 3, 2009 Share Posted August 3, 2009 Is there a php script that will contact an IP, and on a port. If it recieves back, then echo "Online" . else echo "Offline" Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/ Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 lol. yup. can you install PEAR modules? if so, install Net_ping, then create a file with this code as its content: <?php header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Number of times to Ping the host $count = $_GET['count']; // Host we are pinging $url = $_GET['ip']; // This is the Pear Net_Ping class call require_once "Net/Ping.php"; $ping = Net_Ping::factory(); $ping->setArgs(array('count'=>1,'timeout'=>1)); // Set variables. I know I don't have to, but why not do things right? $transmitted = 0; $received = 0; $loss = 0; $text = ""; for ($i=0; $i< $count; $i++){ //Send ping request $output = $ping->ping($url); // If the ping returns no errors, lets parse the results. if (isset($output->_transmitted)){ // Raw data, if you want to see what it returned from the ping (full text) $raw = $output->_raw_data; // This is the transmitted count. if it's zero, that means it failed in transmission. We shouldn't get a zero, but this is to handle that instance $trans = (string)$output->_transmitted; // if it successfully transmitted, lets parse the result, and add it up. if ($trans == 1){ $transmitted++; $received += (string)$output->_received; if ((string)$output->_loss != 0){ $loss++; $text .="."; } else{ $text .="#"; } } else{ $transmitted++; $loss++; $text .="."; } } } echo <<<EOF <?xml version="1.0" encoding="utf-8" ?> <PingResults Version='1.0'> <PingResult Host='$url' Text='$text' Trasmitted='$transmitted' Received='$received' Loss='$loss' /> </PingResults> EOF; ?> now, to use it, do this: http://yourdomain.tdl/ping_file.php?ip=SomeIPOrDomain&count=TimesToPing it will return an xml file. Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-889900 Share on other sites More sharing options...
plznty Posted August 3, 2009 Author Share Posted August 3, 2009 is there a php only solution to this, if not how can i get perl to work Warning: require_once(Net/Ping.php) [function.require-once]: failed to open stream: No such file or directory in /home/webhostg/public_html/failscape.com/ip.php on line 9 Fatal error: require_once() [function.require]: Failed opening required 'Net/Ping.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/webhostg/public_html/failscape.com/ip.php on line 9 Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890047 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 PEAR is a PHP module Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890078 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 Oh, fair warning: if you use my code, don't hit the box more times than you need to. I've ping'd a box 2000 times in less than 6 seconds using this script. It's nasty, but in a good way. Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890080 Share on other sites More sharing options...
plznty Posted August 3, 2009 Author Share Posted August 3, 2009 with my error how can i get it 2 work then Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890098 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 are you on your own server, or remotely hosted? if you're remotely hosted, and you have ssh access, try this pear install Net_php if that fails, you can contact your hosting agency, and request access to PEAR. Other than that, you can always use shell_exec to handle that, but I thin you'll see drastically slower times. Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890106 Share on other sites More sharing options...
plznty Posted August 3, 2009 Author Share Posted August 3, 2009 Where would I find that on CPanel X. Thanks for your support btw Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890111 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 um...can someone take over from here? time for me to go home, so I'll be out of pocket. My son loves my attention when I get in. Link to comment https://forums.phpfreaks.com/topic/168690-contacting-a-address-if-connection-then-return/#findComment-890113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.