Find number of active connections in Linux using various tools

1. Netstat
Netstat (network statistics) is a command-line network utility tool that displays network connections for the Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistics.
Using “netstat -a” will give you something sort of like this (this is a segment of my server):

tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 SYN_RECV
tcp 0 0 41-135-22-100.dsl.mwe:64774 SYN_RECV

As you can see it does name resolving for us and all that good stuff. Sometimes very hand but that’s not what this is about. We want to get some solid numbers so we can take a broader perspective. To do this we can use the following command:

netstat -an | wc -l

Now, If we can check the No of Ips connected to port 80 . which is very helpful to detect the Ddos attack . the command is as under

netstat -tn 2>/dev/null | grep :80 | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -nr | head

Output – Total connections by IP, from highest to lowest.


If you would like to Watching active IP connections

watch -d -n1 ‘netstat -anp | grep -i stream’

2. SS
Socket statistics, or ss for short, is an easy replacement command for netstat. One way to use it, is with parameters ss -aut

-a: show listening and non-listening sockets
-u: show UDP
-t: show TCP

[[email protected] ~]# ss -aut
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:bootpc *:*
tcp LISTEN 0 128 *:ssh *:*
tcp ESTAB 0 0
tcp LISTEN 0 128 :::19531 :::*
tcp LISTEN 0 128 :::ssh :::*

This way it will show similar information to what netstat shows. When using it for very specific requests, you should refer to the man page, as it has some nice options.

Share This :

Use the built-in PHP server in WordPress development

Unlike the traditional development setup which requires to download and config a web server, you can use the built-in PHP server, which doesn’t ask for any complicated configuration like Apache HTTP Server or nginx …

Create a directory where you want to run PHP code,

$ mkdir php-project

$ cd php-project

then start a locally-awesome server,

$ php -S localhost:8000

That’s it, you have a fully-functional PHP web server, good enough for development.

For WordPress, just download the package and extract, access the extracted directory, and start the server.

$ wget -O

$ unzip

$ cd wordpress

$ php -S localhost:8000

You can change the localhost to any of binding network interface on your machine and replace 8000 for any port you want to set for development.

That means, when you want to develop multiple WordPress projects at the same time via one local address, you can spawn each project with different ports. It might be like this,

$ cd project-01

$ php -S localhost:9001 &

$ cd ../project-02

$ php -S localhost:9002 &

$ cd ../project-03

$ php -S localhost:9003 &

Well, I personally think this is much more convenient than manual configuring web server for newly-added projects. It’s also good for newbies to avoid the configuration hell when dealing with whatever XAMPP, LAMP, MAMP, WAMP …

Not only for WordPress, but also for every code running in PHP. Not to mention that many modern PHP frameworks make uses of this today, like Laravel, Lumen, Symfony, CakePHP, CodeIgniter… just to name a few.

Enjoy coding PHP 🙂

Share This :

How to get a VPS stats from SSH bash command line for SolusVM API

The client API is a http based API that allows you and your clients to interact directly with a virtual server with security and easiness. The client API can be disabled at any time. Access is only granted with a key and hash on a per vps basis. We will show you how you can get the solusvm info from SSH bash script . It will be helpful for all of you to use it in different script

The basic command is of this form:

#curl –data “key=$KEY&hash=$HASH&action=info&ipaddr=true&mem=true&hdd=true&bw=true” $SERVERURL/api/client/command.php

This returns data of the form:,325312512,7190880256,4268435456000,115806842,268319649158,0134217728,47583232,86634496,35successmaster.dnsmagic.org134.120.43.51

In script form:
First define variables:


Then execute it from bash:

curl –data “key=$KEY&hash=$HASH&action=$ACTION” “$URL/api/client/command.php”



Share This :

Quality Server Administration Solutions for Businesses

Small businesses do not usually have the funds or the ability to have an in-house IT department at their disposal but their need for quality technology is just as great as any other company. In fact, if your business is completely online then you are totally reliant on the IT expert to get it setup correctly the first time. When you can’t bring the experienced technicians to you then the best option is to outsource and find them online. reading this post

Share This :