The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find list of userdefined ports in aix kittu1979 AIX 1 05-08-2008 05:19 AM
get the list of open ports in unix? zainab UNIX for Dummies Questions & Answers 1 04-14-2008 11:09 AM
unix process that frees ports FunnyCats UNIX for Dummies Questions & Answers 2 10-05-2006 06:18 AM
list all ports and their relative IP@ if any samsal_991 UNIX for Dummies Questions & Answers 4 04-10-2006 12:16 PM
Restrict the number of IP ports that may be dynamically allocated to a process (SUN) itsupplies UNIX for Advanced & Expert Users 2 07-18-2003 06:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2008
vimes vimes is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 46
List TCP ports with process

Hello,

One of our developers is asking for a command/script in Solaris similar to "netstat -anp" in Linux. He gave this output as an example:


Code:
root@xxx:~# netstat -anp | grep LISTEN
tcp        0      0 0.0.0.0:7937            0.0.0.0:*               LISTEN     16082/nsrexecd
tcp        0      0 0.0.0.0:7938            0.0.0.0:*               LISTEN     16082/nsrexecd
tcp        0      0 0.0.0.0:7940            0.0.0.0:*               LISTEN     16082/nsrexecd
tcp        0      0 0.0.0.0:7941            0.0.0.0:*               LISTEN     16082/nsrexecd
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     4257/mysqld
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN     4331/postgres
tcp6       0      0 :::80                   :::*                    LISTEN     4403/apache2
tcp6       0      0 :::22                   :::*                    LISTEN     4163/sshd

Note, the command needs to be used on a Solaris 9 machine (no dtrace). I've been playing around with pfiles for an hour or so now and haven't come up with anything that seems 100% correct.

So I was wondering if you guys have any ideas on how to do this. I don't need a ready-made script (unless you have it), just some pointers to how I can produce a similar output.

Thanks.
  #2 (permalink)  
Old 10-30-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
If you have lsof installed:


Code:
lsof -i TCP|fgrep LISTEN

  #3 (permalink)  
Old 10-30-2008
chihung chihung is offline
Registered User
  
 

Join Date: Jun 2008
Location: Singapore
Posts: 48
See my blog at
Chi Hung Chan: Which process listens to this port (in Solaris)

You should be able to modify the script to come up with something similar to netstat -anp. Just loop through all the LISTEN ports via 'netstat -an | grep LISTEN'
  #4 (permalink)  
Old 10-30-2008
vimes vimes is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 46
Thanks radoulov, I forgot about good ol' LSOF. It's not there, but I'll just install it on the machine. We've not been using lsof lately, since most of our machines are Solaris 10 now and it doesn't seem to give good results there (largely because it can't run in non-global zones).

So I guess my question changes. What do you guys use in Solaris 10 (and zones) as an "lsof -i | grep LISTEN" alternative? (dtrace allowed this time).
  #5 (permalink)  
Old 10-30-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
We don't have many Solaris 10 machines for now so I don't have experience with dtrace but DTrace Tools seem interesting.

Also found this: dtracetoolkit
Look for tcpsnoop.
  #6 (permalink)  
Old 10-30-2008
vimes vimes is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 46
Thanks both.
  #7 (permalink)  
Old 10-30-2008
jlliagre jlliagre is offline Forum Advisor  
ɹǝsn sıɹɐlosuǝdo
  
 

Join Date: Dec 2007
Location: Paris
Posts: 1,465
Here is the ksh oneliner I use.
It needs some reformatting to suit your requirements:

Code:
pfexec pfiles `ls /proc` 2>/dev/null | egrep '^[0-9]|port:' | grep -v "AF_INET6" | sed -e 's/sockname: AF_INET//' -e 's/ *port: /:/'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0