From: Dr. David Kirkby on
On Jul 24, 8:33 pm, Michael Vilain <vil...(a)NOspamcop.net> wrote:
> In article
> <2f956206-15f1-4319-af38-8d67ddb2d...(a)d17g2000yqb.googlegroups.com>,
>  David Kirkby <drkir...(a)gmail.com> wrote:
>
>
>
> > On Jul 24, 5:36 am, hadi motamedi <motamed...(a)gmail.com> wrote:
> > > On Jul 23, 9:17 pm, David Kirkby <drkir...(a)gmail.com> wrote:
>
> > > > I wish to know of a system has a server running at port 8000, and if
> > > > so what its called if possible. I know I can do
>
> > > > $ telnet localhost 8000
>
> > > > but that hangs and one neds to use a control-C, Also, in general, it
> > > > gives no information about that server, though there are exceptions..
>
> > > > I suspect lsof can do this, but that is not a standard part of
> > > > Solaris. (I want to get the information from a script which could be
> > > > run on arbitrary Solairs/OpenSolairs hardware.
>
> > > > Dave
>
> > > You can use 'nmap' to scan for open ports . The 'nmap -O' will give
> > > you more details about the remote node .
>
> > Again, nmap is not a standard command on Solaris. I need to add
> > something to a script that will interrogate someone elses computer for
> > debugging purposes. The script will collect information about CPUs,
> > memory, swap space, hardware etc. But I am particularly interested in
> > knowing if there is a server at port 8000, as the software (Sage maths
> > software) will run a server there if the user choses to do so. Knowing
> > whether that server is there or not would be useful, without programs
> > like nmap.
>
> > Dave
>
> AFAIK, there's no external hardware snoop service that will collect the
> type of information you want remotely.  That sort of thing is usually
> not something you want broadcasted to the world.  I think it's something
> like the 3rd-party configuration tool sysinfo which doesn't do remote
> configurations.  The best you're going to do is find out if port 8000 is
> open on the remote server, again with nmap.  Nothing on vanilla Solaris
> that does this.

I only want to do this on the local host - not remotely.

netstat -na tells me if its open OK.

It would be nice to know what application has it open, but knowing its
open is better than knowing nothing. I only want vanilla Solaris
commands - not lsof, nmap or something like that.

Dave
From: Kees Nuyt on
On Sat, 24 Jul 2010 02:47:00 -0700 (PDT), David Kirkby <drkirkby(a)gmail.com> wrote:

>On Jul 24, 6:59�am, Chris Ridd <chrisr...(a)mac.com> wrote:
>> On 2010-07-24 05:17:52 +0100, David Kirkby said:
>>
>> > I wish to know of a system has a server running at port 8000, and if
>> > so what its called if possible. I know I can do
>>
>> > $ telnet localhost 8000
>>
>> > but that hangs and one neds to use a control-C, Also, in general, it
>> > gives no information about that server, though there are exceptions.
>>
>> > I suspect lsof can do this, but that is not a standard part of
>> > Solaris. (I want to get the information from a script which could be
>> > run on arbitrary Solairs/OpenSolairs hardware.
>>
>> Use "netstat -n", grep the output for "LISTEN" and then your 8000. If
>> the port been opened "on all interfaces", it'll look like "*.8000" in
>> the output. If it is just open on one interface (eg 1.2.3.4), it'll
>> look like 1.2.3.4:8000 instead.
>>
>> I can't think of an easy way to work out what process has it open. The
>> pfiles command can tell you if a given process is listening to a port,
>> but you'd need to run it on each running pid...
>>
>> --
>> Chris
>
>That does not appear to work for me on this OpenSolaris machine
>
>drkirkby(a)laptop:~$ netstat -n | grep LISTEN
>
>But I know there is an SSH server on port 22
>
>drkirkby(a)laptop:~$ telnet localhost 22
>Trying 127.0.0.1...
>Connected to laptop.
>Escape character is '^]'.
>SSH-2.0-Sun_SSH_1.3
>
>Dave

Try pcp:
(may be line wrapped in transfer)
========================================
#!/usr/bin/ksh
#
# PCP (PID con Port)
# v1.10 2010-06-01 Kees Nuyt datadigger @ irc.freenode.net#opensolaris
# Three identical echo "PID..." and echo "___..." in the if branches to one before the if
# `` to $()
# echo to printf
# v1.09 11/12/2009 Sam Nelson sam @ unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# Many thanks Daniel Trinkle trinkle @ cs.purdue.edu
# for the help, much appreciated.
i=0
while getopts :p:P:a opt
do
case "${opt}" in
p ) port="${OPTARG}";i=3;;
P ) pid="${OPTARG}";i=3;;
a ) all=all;i=2;;
esac
done
if [ $OPTIND != $i ]
then
printf "usage: %s [-p PORT] [-P PID] [-a] (Wildcards OK)\n" "$0" >&2
exit 1
fi
shift $(expr $OPTIND - 1)
printf "PID\tProcess Name and Port\n_________________________________________________________\n"
if [ "$port" ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
for proc in $(ptree -a | awk '/ptree/ {next} {print $1};')
do
result=$(pfiles $proc 2> /dev/null| egrep "port: $port$")
if [ ! -z "$result" ]
then
program=$(ps -fo comm= -p $proc)
printf "%s\t%s\t%s\n%s\n" "$proc" "$program" "$port" "$result"
printf "_________________________________________________________\n"
fi
done
elif [ "$pid" ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
for proc in $(ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};')
do
result=$(pfiles $proc 2> /dev/null| egrep port:)
if [ ! -z "$result" ]
then
program=$(ps -fo comm= -p $proc)
printf "%s\t%s\n%s\n" "$proc" "$program" "$result"
printf "_________________________________________________________\n"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
for proc in $(ptree -a | sort -n | awk '/ptree/ {next} {print $1};')
do
out=$(pfiles $proc 2>/dev/null| egrep "port:")
if [ ! -z "$out" ]
then
name=$(ps -fo comm= -p $proc)
printf "%s\t%s\n%s\n" "$proc" "$name" "$out"
printf "_________________________________________________________\n"
fi
done
fi
exit 0
========================================
Best regards,
--
( Kees Nuyt
)
c[_]

From: Greg Andrews on
"Dr. David Kirkby" <david.kirkby(a)onetel.net> writes:
>
>I only want to do this on the local host - not remotely.
>
>netstat -na tells me if its open OK.
>
>It would be nice to know what application has it open, but knowing its
>open is better than knowing nothing. I only want vanilla Solaris
>commands - not lsof, nmap or something like that.
>

There's Wolfgang's advice:

# cd /proc; pfiles * > /tmp/pfiles.out
and then check for the port 8000 in that output.

If you want to make it a single command, you can do something like this:

cd /proc; pfiles * | egrep '^[0-9]+: |port: 8000'

This will produce one line per process (and some errors for processes
that disappeared), but one of the lines will be followed by a second
line with "port: 8000" in it. Then you'll have the process id and the
path/command for the process.

I.e., you'll get partial output for more processes than just the one
that's listening on port 8000, but it'll give you the information
you're looking for.

Since the output of pfiles is multiple lines, it won't be trivial
to block the output you don't want. An awk or perl script could
probably do it, but you'll have to experiment.

-Greg
--
Do NOT reply via e-mail.
Reply in the newsgroup.