Archive for the ‘ PHP ’ Category

Netstat.PHP

This is the script i used tho check our server if someone is trying to do a DDOS attack on our server. Feel free to modify. This script only checks simultaneous connections on port 80.

<?

$netstat = shell_exec(’netstat –protocol=inet -an | grep :80 | cut -c49-100′);
$netstat = explode(’|', substr(preg_replace(’/\s\s+/’, ‘|’, $netstat), 0, -1));

$ips = array();
$status = array();
$combined = array();
$num_connections = count($netstat);

for($i = 0; $i < count($netstat); $i++) {
if($i % 2 == 0) {
array_push($ips, substr($netstat[$i], 0, strpos($netstat[$i], ‘:’)));
} else {
array_push($status, $netstat[$i]);
}
}
unset($netstat);

for($i = 0; $i < count($ips); $i++) {
if(array_key_exists(’$ips[$i]‘, $combined)) {
$combined[$ips[$i]]++;
} else {
$combined[$ips[$i]] = 1;
}
}
unset($ips);
unset($status);

arsort($combined);

print “$num_connections total connections.\n———————-\n”;
print “Remote IP\t  Connections\n”;

foreach($combined as $key => $num) {
print $key . “\t  ” . $num . “\n”;
}
die();

?>

This script when run will check on how many remote IP’s are connected and how many simultaneous connections the IP has. If the IP has more than 10 simultaneous connections then you might want to check who owns that IP and you might need to temporarily block the IP if it makes your server slow to respond.

This is the output of the script when run.

1 total connections.
———————-
Remote IP      Connections

I just remove the IP’s…. :)

Like this blog? Why not buy me a cup of coffee?

What is my IP Address

Do you want to know what is your public IP Address? Here is a small script that you can use to check your IP Address using PHP. You can check my sidebar for your IP Address.

<?

if (getenv(HTTP_X_FORWARDED_FOR)) {
$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);
echo “Your Proxy IP address is : “.$pipaddress. ” (via $ipaddress) ” ;
} else {
$ipaddress = getenv(REMOTE_ADDR);
echo “Your IP address is : $ipaddress”;
}
?>

Like this blog? Why not buy me a cup of coffee?

iTALC - Intelligent Teaching And Learning with Computers. iTalc is an open source software use to monitor, view and control computers on your network or computer laboratory.

I know it is a tedious job to check the works of your students specially during laboratory, You have to go and check their computers individually just to see their progress, But with iTalc you don’t have to roam around the lab to check them, you can just sit and see what your students are doing and can also easily check the sites they are trying to access. What’s best with this software its free and run perfectly with Ubuntu.

For a complete tutorial click here.

Developers site.

Here’s a screenshot.

Like this blog? Why not buy me a cup of coffee?