Operating System - HP-UX
1823369 Members
3128 Online
109654 Solutions
New Discussion юеВ

Find client IP addresses that connecto UNIX server.

 
SOLVED
Go to solution
David Johnson_6
Advisor

Find client IP addresses that connecto UNIX server.

Hello,
I am running HP-UX 11.0 on L2000 HP9000 server. You can run who -r to get the host name of users connected to the system.
How can I get the IP address of that PC.

The server must know the host name , IP, and MAC addresses of all that are connected to it.
IS there a command that will show this information to me?
12 REPLIES 12
Mel Burslan
Honored Contributor
Solution

Re: Find client IP addresses that connecto UNIX server.

This question has been asked recently and the answer is, as long as the dns can resolve the IP address of the host, you will see the dns provided name not the IP. And when it comes to MAC addresses, you are getting into arp/rarp tables and unless you are willing to do some programming, there is no way of getting MAC addresses of connected systems from the OS level commands as far as I know.

To get the host IP addresses you need to wrap your "who -r" command in some sort of a script .
________________________________
UNIX because I majored in cryptology...
Rick Garland
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

With name resolution in place you will get the system name, other wise you will get the IP.

Do not see any options for the MAC

Rick Garland
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

By the way, who -r will tell you what run level you are at.

Use the 'who -RT' or 'who -um'

David Johnson_6
Advisor

Re: Find client IP addresses that connecto UNIX server.

Thank you, for your answers.

I am trying to send a file to a client that is not resolved in DNS. I can get the host name becasue it signs in to the server, but I need the IP address.
Rick Garland
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

A quick/dirty script to help.

LOOKUP=`who -um | awk '{print $NF}'`
nslookup $line


The last field in the 'who -um' will be the name or IP, depending on resolution.

Do the nslookup command the the result. Be it name or IP address you will get a result.

Mel Burslan
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

This is what I came up for listing the "who -R" output with IP addresses instead of hostnames.
(Beware, it is NOT error-proof as it is a quick hack)

who -R | while read u p m d t h
do
hh=`echo $h | cut -d"(" -f2 | cut -")" -f1`
hh1=`echo $hh -cut -c1`
case "$hh1" in
[0-9] ) hip=$hh ;;
* ) hip=`nslookup $hh|grep ^Address|cut -d: -f2|sed -e "1,1s/ //"` ;;
esac
echo $u"\t"$p"\t"$m" "$t"\t"$hip
done
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

Sorry, there was a typo in the above response, which is corrected below

who -R | while read u p m d t h
do
hh=`echo $h | cut -d"(" -f2 | cut -d")" -f1`
hh1=`echo $hh -cut -c1`
case "$hh1" in
[0-9] ) hip=$hh ;;
* ) hip=`nslookup $hh|grep ^Address|cut -d: -f2|sed -e "1,1s/ //"` ;;
esac
echo $u"\t"$p"\t"$m" "$t"\t"$hip
done
________________________________
UNIX because I majored in cryptology...
David Johnson_6
Advisor

Re: Find client IP addresses that connecto UNIX server.

So I am assuming there in no strait out command to get the IP addresses like the you get the host names? I cannot use nslookup to resolve the Host names in DNS. The entries on new client may not be in for weeks at a time.

Last -R, who -u know the host names. Nestat knows the IP address, and arp knows the MAC address. There is no way to put them together without DNS?
Rick Garland
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

Depending on how the /etc/nsswitch.conf is configured and how much info is contained in the /etc/hosts file, you may still be able to use the nslookup command.

To put all together so you can get name, IP, MAC - you will need to script this. No single command to get all of this info.
David Johnson_6
Advisor

Re: Find client IP addresses that connecto UNIX server.

Ok, thank you for your help.
Mel Burslan
Honored Contributor

Re: Find client IP addresses that connecto UNIX server.

As I have stated in my earlier repsonse, info is available but you need to program and put the things together.

arp -a

command will give you the contents of the arp table which will include the hostname (if resolvable by nsswitch.conf/hosts/dns combination) host interface IP address and host interface MAC address in a rather uniform format. All you have to do is use the right combination of, who, grep, cut, awk, nslookup and arp commands to extract the information you need and put them to output of your choice. Wish I had enough time to help you out with the script but today is not one of those days :)
________________________________
UNIX because I majored in cryptology...
Alan Meyer_4
Respected Contributor

Re: Find client IP addresses that connecto UNIX server.

I am confused... If who is giving you the nodename, then it must have some sort of name resolution working for the name/address. Because, as stated before and verified by a test I just ran on my machine, if the name/address does not exist in the DNS, then who -am gives the address in the last column.
" I may not be certified, but I am certifiable... "