Operating System - HP-UX
1837835 Members
2373 Online
110121 Solutions
New Discussion

Re: how to get the service name from the port numbers

 
ramkumar
Valued Contributor

how to get the service name from the port numbers

Hi

I can able to get the port numbers which are having established connections but i could not able to get the services name which are using the port numbers thru any command . i don't want to use the services file because in general some of the port numbers are not listed in services example oracle listener uses listener.ora file instead of services to refer port number .
5 REPLIES 5
Marcel Boogert_1
Trusted Contributor

Re: how to get the service name from the port numbers

Hi there,

$ cat /etc/services

Regards, MB.
bhavin asokan
Honored Contributor

Re: how to get the service name from the port numbers

hi,

use the lsof command to get the service and port.
eg: for port 80 which is a tcp service.

lsof -i tcp:80

and

lsof -i:80

you can get the lsof package from following link .install it
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=653690

regds,
hein coulier
Frequent Advisor

Re: how to get the service name from the port numbers

You can get all the user portnumbers by
netstat -a|grep -e ^tcp -e ^udp
The command will replace all the know port
numbers by their names (/etc/services).

In c there is a function to 'parse' the
services file : getservbyport()
Sridhar Bhaskarla
Honored Contributor

Re: how to get the service name from the port numbers

Hi Ramkumar,

There is no hard and fast rule that every port will have a servicename associated with it. As you said correctly the services lookup file is /etc/services and if the port is not specified there, then there won't be any service name associated with it.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Gerhard Roets
Esteemed Contributor

Re: how to get the service name from the port numbers

Hi Ramkumar

lsof is the way to go ...

Regards
Gerhard