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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.