d.shankar Posted December 17, 2009 Share Posted December 17, 2009 Hi i got this code from the web.. It checks for live and dead socks It is working perfectly on my localhost. but does not work in any webserver ! any ideas ? <?php $filename = "proxies.txt"; //or a localpath. $rel=file_get_contents($filename); $ipset = explode("\n",$rel); // explode it based on your delimiter. foreach($ipset as $ips) { $ipandport=explode(':',$ips); //Porxy string format might be 123.156.189.112:8080 $host=$ipandport[0]; $i=(int)$ipandport[1]; $fp = @fsockopen("tcp://".$host,$i,$errno,$errstr,10); // tcp:// because, socks4 uses TCP and socks5 uses TCP & UDP if($fp) { echo("Result is $fp"); echo ("port " . $i . " open on " . $host . ""); fclose($fp); } flush(); } ?> Waiting for replies..... Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/ Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 i think i have made it out.. just check this code.. <html> <title>Check the Open ports</title> <pre> <font size=3><b>Hai Using this application u can check the ports that are opened in the ip address. If no port is mentioned it will check for the default ports.. <a href="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers" target="_blank">For list of TCP/UDP ports</a> Common Ports Used are FTP 21 SSH 22 Telnet 23 SMTP 25 Web 80 Pop 3 110 IMAP 143 Other Applications Remote Desktop 3389 PC Anywhere 5631</b></font> </pre> <body background="image01.jpg" bgproperties="fixed"> <form action="timer.php" method="POST"> <br><br><br> <table align="center" border="1" bordercolor="black"> <tr> <td align="left" bgcolor="transparent" valign="center">Ip address:<input type=text style="color: #FF0000;font-family: Verdana;font-weight: bold;font-size: 14px;background-color: transparent;" maxlength='30' name=address></td></tr><tr></tr> <tr><td align="left" bgcolor="transparent" valign="center">Port Number:<input type=text style="color: #FF0000;font-family: Verdana;font-weight: bold;font-size: 14px;background-color: transparent;" maxlength='25' name=service></td></tr> <tr><td align="center" valign="center"><input type=submit name=submit value=Submit></td> </tr> </table> </form> </body> </html> <?php error_reporting(0); $address = $_POST['address']; $service = $_POST['service']; if($address && $service) { if(fsockopen($address,$service,$errno,$errstr,10)) { //echo "$address:$service is up!"; echo ("<table><td bgcolor=green width=100% align='center'><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>$address:$service is up!</b></font></td></table>"); } else { //echo "$address:$service is NOT up!"; echo ("<table><td bgcolor=red width=100% align='center'><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>$address:$service is Down!</b></font></td></table>"); } } elseif($address) { include("scanner.class.php"); /* get the target ip address */ $ip_address = gethostbyname("$address"); error_reporting(off); /* set all the require atributes */ $my_scanner = new PortScanner($ip_address,$ip_address); $my_scanner->set_ports("15-25,80,110,143,3306,3389,5631,1337,666"); $my_scanner->set_delay(1); $my_scanner->set_wait(2); /* do the scan and capture the results */ $results = $my_scanner->do_scan(); /* display the results - this simply loops through the ip addresses and indents the results */ foreach($results as $ip=>$ip_results) { echo gethostbyaddr($ip)."\n<blockquote>\n"; foreach($ip_results as $port=>$port_results) { echo "\t".$port." : ".$port_results['pname']." : "; if ($port_results['status']==1) { //echo "open"; echo ("<table><td bgcolor=Green width=100% align='center'><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>Open</b></font></td></table>"); } else { //echo "closed"; echo ("<table><td bgcolor=Red width=100% align='center'><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>Closed</b></font></td></table>"); } echo "<br>\n"; } echo "</blockquote>\n\n"; } } else { } ?> scanner.class.php <? class PortScanner { var $start_ip; /* start of the ip range to scan */ var $stop_ip; /* end of the ip range to scan */ var $current_ip; /* current ip address being scanned (this is for future features) */ var $ports; /* array of ports to be scanned */ var $wait; /* how long to wait for a response from the port */ var $delay; /* how long to pause between each port */ /*** * Function PortScanner() * Class constructor. * Sets the start and end address of the scan range * must be passed... but may be the same. * The end address must be greater than the start address. ***/ function PortScanner($start, $stop) { $this->start_ip = ip2long($start); /* store the start ip address as a long number */ $this->stop_ip = ip2long($stop); /* store the end ip address as a long number */ } /*** * Function set_ports * Adds the passed ports to the array of ports to be scanned. * This can either be a single port, a range of ports e.g. 1-90 * a a combination of both separated by commas (no spaces). ***/ function set_ports($ports) { /* Explode ports into an array based on comma seperation. Will create an array even if there is no comma so no need to check for an array in following code */ $ports_array = explode(",",$ports); /* loop through array of ports */ foreach($ports_array as $key=>$val) { /* try to explode port range into an array */ if(ereg("([0-9]+)\-([0-9]+)",$val, $buff)) { /* loop through range to add each port */ for($ii=$buff[1]; $ii<=$buff[2]; $ii++) { $this->ports[] = $ii; } } else { /* only one port was sent so add that */ $this->ports[] = $val; } } } /*** * Function set_wait * Sets the time to wait for response from socket. * Good object-oriented design doesn't allow access to class * attributes, so accessor functions are provided. ***/ function set_wait($wait) { $this->wait = $wait; } /*** * Function set_delay * Sets the delay between each port check. Delay is in micro-seconds. * Good object-oriented design doesn't allow access to class * attributes, so accessor functions are provided. ***/ function set_delay($seconds=0, $microseconds=0) { $this->delay = (1000000*$seconds) + $microseconds; } /*** * Function do_scan * Does the actual scan, based on the given details (see above functions). ***/ function do_scan() { /* Loop through ip addresses. This is why ip addresses are stored as long numbers as apposed to Internet Protocol dotted addresses */ for($this->current_ip=$this->start_ip; $this->current_ip<=$this->stop_ip; $this->current_ip++) { /* convert the long number back to a dotted address */ $ip = long2ip($this->current_ip); /* loop through the ports and check each */ foreach($this->ports as $key=>$port) { /* for unix systems, this will obtain the name of the service running on that port. Win32 systems will just return N/A. */ if (!getservbyport($port,"tcp")) {$pname = "N/A"; } else {$pname = getservbyport($port,"tcp"); } /* attempt to open a socket to the port at the current ip address */ $ptcp = fsockopen($ip, $port, &$errno, &$errstr, $this->wait); if($ptcp) {$status=1; } /* return 1 for open port (so users can display their own message */ else {$status=0; } /* return 0 for closed port (so users can display their own message */ /* return the results in a structured multi-dimensioned array so the user can choose how to display the results */ $results["$ip"]["$port"]["pname"] = "$pname"; $results["$ip"]["$port"]["status"] = "$status"; /* start the delay before moving on to the next port */ $this->do_delay($this->delay); } } /* returnt the results to the user */ Return $results; } /*** * Function do_delay * This pauses execution for the passed length of time (micro-seconds) * This allows a delay of less than 1 second for system which do not * support usleep (Win32). * This code was post on the PHP manual by "dsc at c2i dot net" * I'm not sure if this works or not, so if your running *nix you * may want to change this to use usleep(); ***/ function do_delay($delay) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while ($timePassed < $delay); } } ?> Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978947 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 the reason for your code might not be working on the server is that either ur antivirus could have blocked the port scanning.. or else ur app might have been using the large part of CPU..so that it could have stopped executing after 10 seconds i too have uploaded it to my server it using max cpu so i have removed it off. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978949 Share on other sites More sharing options...
corbin Posted December 17, 2009 Share Posted December 17, 2009 If it's cheap or free web hosting, fsockopen might be disabled. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978952 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 i have tested on a free web hosting but it is open there. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978954 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 fso If it's cheap or free web hosting, fsockopen might be disabled. FYI, fsock is enabled in that server dude. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978956 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 d i have tested on a free web hosting but it is open there. dude is that working in that free webserver ? Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978957 Share on other sites More sharing options...
trq Posted December 17, 2009 Share Posted December 17, 2009 Have you tried removing the error suppressor so you can actually see if you get any errors? Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978958 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 yes it is working.. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978960 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 Have you tried removing the error suppressor so you can actually see if you get any errors? Yea dude i tried like this. I get a white blank page , but it works on my localhost <?php set_time_limit(0); error_reporting(E_ALL); $filename = "proxies.txt"; //or a localpath. $rel=file_get_contents($filename); $ipset = explode("\n",$rel); // explode it based on your delimiter. foreach($ipset as $ips) { $ipandport=explode(':',$ips); //Porxy string format might be 123.156.189.112:8080 $host=$ipandport[0]; $i=(int)$ipandport[1]; $fp = fsockopen("tcp://".$host,$i,$errno,$errstr,10); // tcp:// because, socks4 uses TCP and socks5 uses TCP & UDP if($fp) { echo("Result is $fp"); echo ("port " . $i . " open on " . $host . ""); fclose($fp); } flush(); } ?> Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978967 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 yes it is working.. dude what is the free webhost you are using ? why did it didnt work on your server but it works on free server ??? Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978968 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 i am using the x10hosting and it is working. i think in ur code u need to set the delay for it to work. it is going for a time out. by the way how many ips u have placed in the proxies.txt file. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978970 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 just a single one. even that doesnt work ! Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978971 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 have u tried using my code instead and cheked in ur server is it working?? Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978972 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 dude thats a port scanner. i need to check socks. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978973 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 dude thats a port scanner. i need to check socks. can u paste a sample ip which u will be scanning.. if u could paste the txt file which u are using then more useful Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978974 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 24.46.154.228:6407 just copy it in a textfile and name it as proxies.txt Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978975 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 ok i have checked it out..and the thing is i dont find any difference between what u are doing and wht i have written forgetting abt the input part. so if u dont give the port number in my code it will search for some of the default ports and it will check whether they are open are not. i think u can use my code and change the input part.. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978976 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 dude the code shows the same result as mine ! it works in localhost , but not in the webserver !!! i am so confused ???????? Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978979 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 so in ur sever also is it not working, i mean my code which i have pasted Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978980 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 yea dude .. i checked in 3 diff servers Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978981 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 check these values in the php.ini default_socket_timeout max_execution_time if it is default 60 increase the values on the server.. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978982 Share on other sites More sharing options...
d.shankar Posted December 17, 2009 Author Share Posted December 17, 2009 dude just a question... we are just checking a single ip&port and it returns it is down within 10 seconds.. s i think we dont need to increase the timeout.. because the script stops within 10 seconds or less. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978983 Share on other sites More sharing options...
Deoctor Posted December 17, 2009 Share Posted December 17, 2009 dude just a question... we are just checking a single ip&port and it returns it is down within 10 seconds.. s i think we dont need to increase the timeout.. because the script stops within 10 seconds or less. dude i know that but just for checking increase and see, coz sometimes the server can nnot proceed until the delay time or else the web administrator might have blocked the scripts such as this. Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978985 Share on other sites More sharing options...
trq Posted December 17, 2009 Share Posted December 17, 2009 Quit it with the dudes you sound like a flashback to the 80's. Place this code at the top of your code. <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> Link to comment https://forums.phpfreaks.com/topic/185435-this-code-is-strange/#findComment-978994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.