Operating System - HP-UX
1832645 Members
2595 Online
110043 Solutions
New Discussion

"lsof -i" and "netstat -an"

 
yc_2
Regular Advisor

"lsof -i" and "netstat -an"

Hi,

Correct me if I'm wrong that
"lsof -i tcp:49153" is the same as
"netstat -an | grep 49153" ?

If so, why there was no output when I did
"lsof -i tcp:49153"

but when I did "netstat -an | grep 49153" I got the following:

tcp 0 0 *.49153 *.* LISTEN

Appreciate any advice.
8 REPLIES 8
Jerome Baron
Respected Contributor

Re: "lsof -i" and "netstat -an"

Hi

You are right. On my system :
# netstat -an | grep 49152
tcp 0 0 IP.49159 IP.49152 ESTABLISHED
tcp 0 0 *.49152 *.* LISTEN
tcp 0 0 IP.49152 IP.49159 ESTABLISHED
# lsof -i tcp:49152
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpc.statd 591 root 3u inet 72,0xb 0t0 TCP *:49152 (LISTEN)
rpc.statd 591 root 7u inet 72,0xb 0t0 TCP host:49159->host:49152 (ESTABLISHED)

Have you a good lsof version ?

Regards,
Jerome
Michael Tully
Honored Contributor

Re: "lsof -i" and "netstat -an"

yc_2
Regular Advisor

Re: "lsof -i" and "netstat -an"

Hi,

I removed the current version of lsof and downloaded and installed the lsof-4.64 but the result still the same.

Anyway, how do I know what application is using the port and how do stop it from listening ? My auditor is chasing me.


Thanks in advance,
YC
Jerome Baron
Respected Contributor

Re: "lsof -i" and "netstat -an"

you can try lsof -n |grep 49153

Jerome
yc_2
Regular Advisor

Re: "lsof -i" and "netstat -an"

Hi Jerome,

Sorry to say the prompt just come back without any result.
Jerome Baron
Respected Contributor

Re: "lsof -i" and "netstat -an"

does the lsof on an another port give you a correct output ?

Regards,
Jerome
rick jones
Honored Contributor

Re: "lsof -i" and "netstat -an"

lsof and netstat are _similar_ but not the same. lsof is trying to lookup much more than netstat reports. perhaps it does not always get it right.

i would make sure that you compile lsof on the system on which you wish to use it to make sure that the binary you use matches the kernel you are running (btw, you did boot off /stand/vmunix yes?)

also, try lsof against some other port numbers and see if it "works" there.
there is no rest for the wicked yet the virtuous have no pillows