Netstat to listen to another device, how can I find the result?


I have found some good tips about using netstat on :

One particular tip I’d like to ask is to listen to traffic of a specific IP address, with this:

netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n

I already run the command and don’t know where the output is saved.

How can I find the output file?


Welcome @huskylove

The output is not saved anywhere else. You will get outputs on the screen if matched by grep. That is all. With your command I would say you might only see output as follows:

       1 CLOSE_WAIT

Try replacing $6 with $5 in awk:

netstat -nat |grep IP | awk '{print $5}' | sort | uniq -c | sort -n
netstat -nat |grep  '' | awk '{print $5}' | sort | uniq -c | sort -n

Now I see:


Is that what you want?

oh yes, thanks. I will try this immediately. The problem is I didn’t see any result after the command is executed. That’s why I asked.

Nope, I didn’t see any output. I can use the command for IoT device such as IP Camera, can’t I?

Is this standard Linux box? IoT? Router? The netstat command may not work on IoT or router as those use different version. Try debugging command one by one. Start with

netstat -nat

Do you see output? If so, add next part:

netstat -nat | grep

Try out and let me know how it went.

Command netstat -nat returned all active internet connections from my device (Lenovo with Kali Linux) to foreign addresses.

This command didn’t return any output:

I changed the ip address with IP address of the camera, didn’t return anything.

Which tool can I use for listening particular port of an ip camera?

IS the camera using UDP? The -nat only looks for TCP connection. For UDP add -u

netstat -natu | grep IP

Hi Raj,

the camera is using TCP and UDP.

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki