Jump to content

Little help please


porko2004

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/140500-little-help-please/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735829
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-735833
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-736077
Share on other sites

  • 2 weeks later...

<?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.

Link to comment
https://forums.phpfreaks.com/topic/140500-little-help-please/#findComment-748246
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.