porko2004 Posted January 12, 2009 Share Posted January 12, 2009 i got this code which counts all connections to a port. but when i connect to port instead of showing 1 it show 2 can anyone please help me. <?php $serverip="172.0.0.1"; $sql_hostname = "localhost"; $l2j_database = "cq"; $sql_username = "test"; $sql_password = "test"; $db_connect = mysql_connect($sql_hostname, $sql_username, $sql_password) or die ('The server is down.'); ob_start(); system("netstat -n"); $result=ob_get_contents(); ob_end_clean(); //TCP 172.0.0.1:5816 ESTABLISHED preg_match_all("/TCP.*:5816.*ESTABLISHED/mi",$result,$match); $online=count($match[0]); print("<br>Players Online: <b>".$online."</b>"); mysql_close($db_connect); ?> Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/ Share on other sites More sharing options...
beyzad Posted January 12, 2009 Share Posted January 12, 2009 Do you mean: $serverip="127.0.0.1"; ??? Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735233 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 thats how i got it for now as test but after it will be an ip i need it to count peoples connectiosn to an ip and port but instead of show 1 connection for 1 person it shows 2 please help me Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735745 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 If its showing two that meens there are two connections to that port. Do you want a false reading? Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735749 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 the reading is not correct casue i tell 2 people to connect and it shows 4 not 2 plese look at the script and tell me whats wrong plz Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735756 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 Try.... <?php $online = exec("netstat -n | grep 5816 | wc -l") / 2; print "<br>Players Online: <b>".$online."</b>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735768 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 that code doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735813 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 Works as expected here, sorry. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735824 Share on other sites More sharing options...
corbin Posted January 13, 2009 Share Posted January 13, 2009 I don't think grep is on Windows natively. (Apparently it's in my PATH, but I think it's coming from Cygwin.) $online = exec('netstat -n | find "ESTABLISHED" | find "5816" | wc -l') / 2; Not sure if there's a Windows version of wc.... Well, I'm sure there is, but natively. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735829 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 As your using an ob call the server it's self is connecting to the db as well as your script process(link) this creates your double result just simply $result = number_format(count[$match[0]/2,0); or someother resulting way. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735830 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 I don't think grep is on Windows natively. (Apparently it's in my PATH, but I think it's coming from Cygwin.) $online = exec('netstat -n | find "ESTABLISHED" | find "5816" | wc -l') / 2; Not sure if there's a Windows version of wc.... Well, I'm sure there is, but natively. Eww. You know, I forget windows even exists sometimes. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735833 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 to which script i add that code. mine or the admins Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735834 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 please help me Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736000 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 please help me resolve this problem please Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736069 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 i found this code <?php $ports = array('5816', '9958'); $total = 0; foreach ($ports as $port) { $total += shell_exec("netstat | grep $port | wc -l"); } echo $total; ?> but it appears as 0 when people are connecting to the port please help Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736077 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 Are you on windows or Linux? Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736291 Share on other sites More sharing options...
porko2004 Posted January 13, 2009 Author Share Posted January 13, 2009 im using windows Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736552 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 $total += shell_exec("netstat | findstr $port | wc -l"); Not sure on the WC part but Grep Equiv for Windows might help for the grep part Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736554 Share on other sites More sharing options...
porko2004 Posted January 25, 2009 Author Share Posted January 25, 2009 $total += shell_exec("netstat | findstr $port | wc -l"); Not sure on the WC part but Grep Equiv for Windows might help for the grep part Mate that didnt help me. is there any other way to get this working Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-745659 Share on other sites More sharing options...
porko2004 Posted January 28, 2009 Author Share Posted January 28, 2009 <?php echo (exec('netstat -a -n |find "5816" |find "ESTABLISHED" /c')0); ?> how do i fix this Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-748244 Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 <?php echo (exec('netstat -a -n |find "5816" |find "ESTABLISHED" /c')0); ?> Why is that 0 there? Also, is exec working correctly? Just just doing: <?php echo exec('netstat -n'); ?> and make sure the ouput is what you would expect. That works fine for me if I put in place of 5816 a port I have connections on. Quote Link to comment https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-748246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.