Which application has a TCP socket open


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Which application has a TCP socket open
# 1  
Old 10-25-2005
Which application has a TCP socket open

If I do a netstat -a I can see all the sockets currently open, is there a way that I can tell which application is holding open these sockets ?
# 2  
Old 10-25-2005
Use the public domain program called lsof.
# 3  
Old 10-25-2005
At least one known implementation of netstat, i.e. the Linux version I use here, has the -p option to see the program ID/executable. It's probably an extension.

Example:

Code:
[root@bernardchan root]# netstat -ap
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 localhost:32768         *:*                     LISTEN      1425/xinetd
tcp        0      0 *:32769                 *:*                     LISTEN      -
tcp        0      0 *:nfs                   *:*                     LISTEN      -
tcp        0      0 *:cvspserver            *:*                     LISTEN      1425/xinetd
tcp        0      0 *:ldap                  *:*                     LISTEN      6332/slapd
tcp        0      0 *:1000                  *:*                     LISTEN      1245/rpc.ypxfrd
tcp        0      0 *:649                   *:*                     LISTEN      892/ypserv
tcp        0      0 *:mysql                 *:*                     LISTEN      1878/mysqld
tcp        0      0 *:942                   *:*                     LISTEN      1611/rpc.mountd
tcp        0      0 *:pop3                  *:*                     LISTEN      1425/xinetd
tcp        0      0 *:sunrpc                *:*                     LISTEN      811/portmap
tcp        0      0 *:http                  *:*                     LISTEN      2062/httpd2
tcp        0      0 *:10000                 *:*                     LISTEN      1906/perl
tcp        0      0 *:ftp                   *:*                     LISTEN      1819/proftpd: (acce
tcp        0      0 bernardchan.loca:domain *:*                     LISTEN      1377/named
tcp        0      0 localhost:domain        *:*                     LISTEN      1377/named
tcp        0      0 *:ssh                   *:*                     LISTEN      1401/sshd
tcp        0      0 *:39831                 *:*                     LISTEN      6394/artsd
tcp        0      0 *:ipp                   *:*                     LISTEN      1470/cupsd
tcp        0      0 localhost:smtp          *:*                     LISTEN      1774/master
tcp        0      0 localhost:rndc          *:*                     LISTEN      1377/named
tcp        0      0 *:634                   *:*                     LISTEN      876/rpc.statd
tcp        0      0 *:https                 *:*                     LISTEN      2062/httpd2
tcp        0      0 *:ldaps                 *:*                     LISTEN      6332/slapd
udp        0      0 *:32768                 *:*                                 1377/named
udp        0      0 *:nfs                   *:*                                 -
udp        0      0 *:32770                 *:*                                 -
udp        0      0 *:646                   *:*                                 892/ypserv
udp        0      0 *:10000                 *:*                                 1906/perl
udp        0      0 *:939                   *:*                                 1611/rpc.mountd
udp        0      0 bernardchan.loca:domain *:*                                 1377/named
udp        0      0 localhost:domain        *:*                                 1377/named
udp        0      0 *:956                   *:*                                 1627/rpc.yppasswdd
udp        0      0 *:998                   *:*                                 1245/rpc.ypxfrd
udp        0      0 *:sunrpc                *:*                                 811/portmap
udp        0      0 *:628                   *:*                                 876/rpc.statd
udp        0      0 *:ipp                   *:*                                 876/rpc.statd

Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     979557 6381/fam            /tmp/.fam_socket
unix  2      [ ACC ]     STREAM     LISTENING     4215   1774/master         private/old-cyrus
unix  2      [ ACC ]     STREAM     LISTENING     4219   1774/master         private/cyrus
unix  2      [ ACC ]     STREAM     LISTENING     4223   1774/master         private/uucp
unix  2      [ ACC ]     STREAM     LISTENING     4227   1774/master         private/ifmail
unix  2      [ ACC ]     STREAM     LISTENING     4231   1774/master         private/bsmtp
unix  2      [ ACC ]     STREAM     LISTENING     3557   1358/saslauthd      /var/lib/sasl2/mux

# 4  
Old 10-26-2005
That's really useful, thanks guys, my netstat does not support -p, but I have downloaded lsof

Thanks again

M
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to repair a TCP/IP socket in state: CLOSE_WAIT?

Hi The clients connect to my server -using port 9130. But no client could connect to my server at this time. I've checked already and this is the result netstat -Aan|grep -v 127.0.0.1|grep 9130|pg f10006000abcb398 tcp4 10313 0 10.0.89.81.9130 10.158.70.24.1705 CLOSE_WAIT... (8 Replies)
Discussion started by: bobochacha29
8 Replies

2. Solaris

Installing TCP-MUX protocol socket help required.

I been looking for a good guide or some help on how to install and setup TCP-MUX protocol socket on my Solaris 7 servers. Can anyone point me in right direction of help me ? Thanks (5 Replies)
Discussion started by: Wpgn
5 Replies

3. Solaris

Tcp Socket (Connection refused) to my server box

I installed a fresh copy of Solaris 7 and present up my ip and domain for my web services but when I try to connect to it I get the following error; TCPActiveOpen: connect failed tcp/192.168.1.148/7900: 146 (Connection refused). the port is open in my router but I don't no were to add it in... (5 Replies)
Discussion started by: Wpgn
5 Replies

4. Shell Programming and Scripting

Read and write to tcp socket

Hello all, I have a requirement to read and write to a tcp socket from an HP-UX shell script. I see a /dev/tcp character device on my servers: crw-rw-rw- 1 root root 72 0x00004f Mar 28 18:37 /dev/tcp So I believe this is what I should use. The problem is that all the... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

5. IP Networking

Packets sent from Linux TCP socket

Hello, Our software is using a TCP socket (AF_INET, SOCK_STREAM) to communicate with an Ethernet device. When we send a message, the message object writes itself in full onto the socket's stream buffer before the software invokes send() from socket.h. I'm still researching, but have 2... (1 Reply)
Discussion started by: bix_20002000
1 Replies

6. Programming

Using socket to test a TCP port

Hello, I'm trying to write a small c application to test a tcp port. This works fine for the most part but the default timeout on the connect is very long. I have been reading many posts but and it looks like I need to set the socket to be non-blocking and poll for a result. I have been totally... (2 Replies)
Discussion started by: tjones1105
2 Replies

7. IP Networking

Unknown open port: "6881/tcp open bittorrent-tracker" found with nmap

Hi. I ran nmap on my server, and I get the following: Starting Nmap 4.76 ( http://nmap.org ) at 2009-03-19 16:33 EDT Interesting ports on -------- (-----): Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 6881/tcp open bittorrent-tracker The... (0 Replies)
Discussion started by: Rledley
0 Replies

8. Programming

problem receiving data from TCP socket

Hi all, I'm writing a socket program which sends a structure from one machine to another. When I run my client first time it runs well, however after the first time I couldn't receive all the data inside the structure (it is like, half of the array is received and the other half is not set). I... (1 Reply)
Discussion started by: SaTYR
1 Replies

9. AIX

TCP/IP socket binding problem

I have what appears to be a unique socket problem, although admittedly my tcp/ip programming experience is relatively limited. I have a AIX server process using TCP/IP berkely sockets, and a Windows (C#) process. The windows process takes input from a user and sends a message to the Unix... (1 Reply)
Discussion started by: adiaconou
1 Replies

10. Programming

Confusion about TCP/IP socket programming

Hello there chaps. First of all, i'm no TCP/IP-wiz, so forgive me if this is a stupid question. I've been messing around with filetransfer using sockets, and there is one thing that confuses me. This is how it's set up: A server app listens on a port for a client connection. When it... (3 Replies)
Discussion started by: crippe
3 Replies
Login or Register to Ask a Question