Jump to content

how to show online players by connected ports? Help pls


sango

Recommended Posts

alright guys..
i need a simple help here


right now, im hosting a gameserver, the players are connected on 5 different ports
i want to make a php script which shows how many players are online currently.

so, how to make the script which adds up all the players on the 5 ports?

ports are 1234 1235 1236 1237 1238
this is from netstat -n cmd

218.212.16.144:55901   58.182.121.251:22938   ESTABLISHED
218.212.16.144:55901   121.6.38.32:1225       ESTABLISHED
218.212.16.144:55901   200.109.29.190:1805    ESTABLISHED
218.212.16.144:55901   201.252.106.219:3893   ESTABLISHED
218.212.16.144:55901   202.156.20.146:1773    ESTABLISHED
218.212.16.144:55901   202.156.44.183:1352    ESTABLISHED
218.212.16.144:55901   202.156.149.71:1572    ESTABLISHED
218.212.16.144:55901   202.156.173.239:1824   ESTABLISHED
218.212.16.144:55901   202.156.185.145:1110   ESTABLISHED
218.212.16.144:55901   218.186.153.117:1925   ESTABLISHED


for example there are 10 connections for port 55901

thus it will show 10 players are connected

i want to do this also for 5 different ports
You could pass a command to CMD like netstat -n | find "ESTABLISHED" then explode that apart and check if the local port is port 1234 and if it is increment a variable...

Not gonna come up with the code for you, but thats how you could do it...
You could try this, but I havent (can't) tested it.

[code]
<?php
  $ports = array('1234', '1235', '1236', '1237', '1238');
  $total = 0;
  foreach ($ports as $port) {
    $total += shell_exec("netstat | grep $port | wc -l");
  }
  echo $total;
?>
[/code]

Im also not sure how reliable that might be but it should give you the idea. Most of the work is done within the shell, not really php.

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.