LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2017, 06:08 PM   #1
nix84
Member
 
Registered: Apr 2014
Posts: 276

Rep: Reputation: Disabled
How to monitor sockets


I found some info on using bash and netcat to monitor ports/sockets. I am wanting to watch all ports for activity and notify me.
Some ports are set up by the browser for info coming back from their targets. Is there a way to find which ports a browser has set up like this? My goal is to notify me when a port is active and by whom. Is there a quick way to do this with bash/netcat/netstat?
Does the netstat (lipt -I think is what I used) listing of listening ports really include all active ports?
Checking for open/closed ports across ALL registered ports is a major task time wise event with netcat/nc/ncat. Is there a really fast way to do that? Lots of questions but all related to monitoring ports so thanks for the help.

Last edited by nix84; 08-16-2017 at 06:09 PM.
 
Old 08-17-2017, 10:02 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Many ports are ephemeral so tools that check for them on the fly will only see them if they happen to be active at the moment the command was run. The best way to monitor ports in general is to use a tool like tcpdump or wireshark which captures traffic as it occurs. If you look at the man page (e.g. man tcpdump) you can see it will allow you to specify which interface, which port, which destinations, which source etc... using various flags.

For quick glimpse of things I prefer to use "lsof -i". Other flags in lsof will let you specify numeric values rather than name lookups.

Ports aren't "registered" - they are used on demand. The /etc/services file has well known ports and purposes but in reality one can use any port that isn't already in use. Ports below 1000 can only be started by root.

Most traffic has 2 connections (at least) with one side being a well known and defined port for the application (e.g. port 80 for http or 443 for https, 22 for ssh, etc...) but a lot of the connections on the other side will use random ports. So for example traffic going to port 80 on your web server will always have port 80 on one side of the connection but could have many different ports for different connections on the other side. In such situations it is better to pay attention to the IP part of the socket than the port part.
 
Old 08-18-2017, 05:43 PM   #3
nix84
Member
 
Registered: Apr 2014
Posts: 276

Original Poster
Rep: Reputation: Disabled
Thanks 4 UR input but btw ncat/netcat/nc will allow for continuous monitoring (listening).
1) Still need a solution as to where bowsers keep a list of ports they are currently employing to download info and responses from web servers.
2) are the listening ports shown by netstat truly ALL that are active?
3) has anyone used bash and tcpdump/netcat/et. al. to monitor and alert the pc/server user of transgressions?
Also the registered ports are 1025=49151 like dynamic are 49152-65535 and reserved/well known are 1-1024 sorry for confusion that may have created.

Last edited by nix84; 08-18-2017 at 05:47 PM.
 
Old 08-22-2017, 01:18 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by nix84 View Post
Thanks 4 UR input but btw ncat/netcat/nc will allow for continuous monitoring (listening).
"LISTEN"ing on a port is not the same thing as "monitoring" it. When port is being "LISTEN"ed on it is simply waiting for connections to be made to it. When a connection is "ESTABLISHED" it is established to a port that was LISTENing.

From your original post you were using nc to "LISTEN" and to "ESTABLISH" but wanted to be able to "monitor" the connections. My response was to the "monitor" part of the question.

If the connection is ESTABLISHED and active then lsof -i will show it to you as a point in time. If you're doing active traffic you want to do tcpdump to capture it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ps -? to monitor sockets? jmurch Linux - Server 1 09-01-2011 04:35 AM
Sockets sanjaykhuntia Linux - Networking 1 10-31-2007 05:08 AM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 10:49 AM
Sockets on RH 9.0 rjs2006 Linux - Newbie 1 01-17-2005 11:16 PM
sockets andox Programming 4 07-05-2003 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration