Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Wed Aug 23, 2017 9:01 am


Internet Protocol, Transport Control Protocol, Network protocols, Routing, Routers, IP aliases, Routes, Ethernet

Author Message
mandrei99
Post  Post subject: FreeBSD find pid that opened TCP/UDP socket without lsof using address of protocol control block(PCB  |  Posted: Wed Dec 11, 2013 4:56 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
 

FreeBSD find pid that opened TCP/UDP socket without lsof using address of protocol control block(PCB

FreeBSD find pid that opened TCP/UDP socket without lsof using address of protocol control block(PCB)

LSOF (list open files) is a useful tool coming from Linux world that can show file descriptors, socket information and much more. It does not come by default in FreeBSD and can be installed from ports or source.

If "lsof" is not installed, another way of finding the process ID of the process that opened a TCP or UDP socket is by using the Protocol Control Block (PCB) and "netstat" and "fstat" commands that are both part of the FreeBSD base system.

Find the PCB of an open port using netstat:
Code:
# netstat -Aanf inet | grep 22
c2de3910 tcp4       0      0 *.22               *.*                LISTEN


The output is the PCB,protocol , rec/send Queues, local address and foreign address.

Now let's find the process associated to this PCB:
Code:
# fstat | grep c2de3910
root     sshd       87382    3* internet stream tcp c2de3910
# ps alxw | grep -v grep | grep  87382
    0 68846 87382   0  44  0  8344  2928 select Ss    ??    0:00.16 sshd: root@ttyp0 (sshd)
    0 70595 87382   0  44  0  8344  2928 select Ss    ??    0:00.24 sshd: root@ttyp1 (sshd)
    0 87382     1   0  44  0  5784  2184 select Is    ??    0:01.96 /usr/sbin/sshd


Obviously, SSH.





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "FreeBSD find pid that opened TCP/UDP socket without lsof using address of protocol control block(PCB"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. FreeBSD how to sniff a unix socket using "socat" utility.

mandrei99

0

2305

Thu Dec 12, 2013 6:13 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD and Linux: How to find live hosts on a directly connected subnet with ping

mandrei99

0

1001

Mon Jan 12, 2015 9:24 am

mandrei99 View the latest post

There are no new unread posts for this topic. PTP/IP. Picture transfer protocol

Stevo

0

513

Sun Nov 29, 2015 6:38 pm

Stevo View the latest post

There are no new unread posts for this topic. Linux How to change hardware MAC address of an interface

debuser

1

892

Tue Dec 06, 2011 6:26 am

Zettie49 View the latest post

There are no new unread posts for this topic. KVM: List MAC address table and interface that learned them.

mandrei99

0

1263

Sun Feb 01, 2015 6:26 am

mandrei99 View the latest post

There are no new unread posts for this topic. IPv6 tunnel - Debian Linux and tunnelbroker.net - IPv6 in IPv4 (ip protocol 41)

mandrei99

0

1637

Sun Feb 01, 2015 4:17 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to block ping icmp echo requests without a firewall in Linux

debuser

0

833

Mon Nov 26, 2012 9:46 am

debuser View the latest post

There are no new unread posts for this topic. FreeBSD PF supported icmp types

admin

0

1137

Fri Jan 28, 2011 9:15 am

admin View the latest post

There are no new unread posts for this topic. FreeBSD - multiple routing tables

mandrei99

0

4820

Wed Aug 28, 2013 8:40 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD: How to list IPv6 neighbors

mandrei99

0

1941

Mon Oct 06, 2014 10:00 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO