NETSTAT
✅ What is NETSTAT?
NETSTAT (Network Statistics) is a command-line network utility that displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
👉 In simple words:
Shows all active connections (inbound and outbound) on a computer.
Helps monitor which ports and IP addresses are communicating.
Useful for network troubleshooting, performance, and security checks.
💡 Why is NETSTAT Important?
View active network connections
Know who/what your computer is communicating with.
Check listening ports
See which services are open and waiting for connections.
Monitor open and used ports
Identify potential security risks (e.g., malware).
See routing tables
Understand how data is routed on your network.
Analyze network stats
Monitor traffic and interface status.
⚙️ Basic Syntax of NETSTAT:
📊 Key NETSTAT Options:
-a
Show all active connections and listening ports
netstat -a
-n
Show addresses and port numbers in numeric form
netstat -n
-o
(Windows)
Show owning process ID (PID) for each connection
netstat -o
-p
(Linux/Mac)
Show process using the connection
netstat -p
-r
Display routing table
netstat -r
-e
Display Ethernet statistics
netstat -e
-s
Show per-protocol statistics (TCP, UDP, etc.)
netstat -s
-b
(Windows)
Show program name using each connection
netstat -b
📜 Example NETSTAT Output:
🧠 Explanation of Columns:
Proto
Protocol used (TCP or UDP).
Local Address
Local machine's IP address and port.
Foreign Address
Remote machine's IP address and port.
State
Status of the connection (e.g., ESTABLISHED, LISTENING).
🔑 Common States in NETSTAT (TCP):
LISTENING
Waiting for incoming connection.
ESTABLISHED
Active connection established.
CLOSE_WAIT
Waiting for connection to close.
TIME_WAIT
Waiting to ensure remote side received acknowledgment.
SYN_SENT
Connection attempt sent; waiting for reply.
SYN_RECEIVED
Acknowledgment received; waiting for final ACK.
✅ Common Uses of NETSTAT:
Check active connections (IP + Port + State):
See which process (PID) is using a port (Windows):
Display programs using connections (Windows, admin mode):
View routing table:
See all listening ports:
📌 Sample Scenario: How to Detect Malware Using NETSTAT
If you suspect malware or unknown apps are connecting to the Internet:
Check suspicious connections.
Find PID.
Open Task Manager → "Details" tab → Match PID to process.
Investigate or terminate the suspicious process.
🔐 Security Tip with NETSTAT:
Regularly monitor open ports and active connections.
Close unnecessary listening ports.
Investigate unknown IP addresses.
Use firewalls to block unwanted traffic.
🚦 Interpreting NETSTAT Results:
Many established connections to unknown IPs
Possible malware or unauthorized connections.
Unexpected listening ports
Potential backdoor or unauthorized service.
High TIME_WAIT or CLOSE_WAIT states
Possible issue with application closing connections.
✅ Summary:
Purpose
Monitor network connections, ports, and routing.
Platform
Windows, Linux, macOS (via net-tools package).
Common Commands
netstat -an
, netstat -r
, netstat -o
.
Useful For
Security, troubleshooting, and performance monitoring.
Last updated