Get List of users+IPs

Hello!

We have an AIX box (6.3), we are looking for a way to get list of logged in users and their IP. The issue we have is running

who -ub

shows hostname and we are wanting to get the ip. Any suggestions of ideas? Thanks in advance for any help!

First off it's not AIX6.3 but AIX6.1,
If who -ub is showing you hostname, that means your DNS is resolving the IP to hostname.
Just do nslookup <hostname> , it should give you IP address.

I was bored... :slight_smile:

IFS=;who -ub | while read LINE;do IP=$(echo $LINE|sed -n "s/.*(\(.*\)).*/\1/p"|xargs -I{} dig +short {});echo $LINE|sed "s/(.*)/($IP)/g";done

Maybe there is a more elegant way.

Regards

I'd think that's only guaranteed to work if the host the user is coming from has only one IP address. Admittedly that will cover the vast majority of cases.

Also, the root cause of the problem is probably the data stored in the utmpx file contains a string that's already been converted to the hostname, almost certainly at login. I'm not sure offhand how to prevent the login process from recording a hostname instead of an IP address in the utmpx data.

For SSH it is possible to disable the DNS reverse lookup(-u0):
https://www.linux-tips.org/article/92/disabling-reverse-dns-lookups-in-ssh
But this can impact other sshd options:
SSH slow to login? Disable reverse DNS lookup - Arun Stephens

Regards