Plucka
asked on
Determine My IP Address
Hi,
I'm writing a perl script for firewall configuration and I need a way of determining my ip address into a variable.
Ie: The ip address of the person telnetted / ssh'd into the system and running the script.
I'm writing a perl script for firewall configuration and I need a way of determining my ip address into a variable.
Ie: The ip address of the person telnetted / ssh'd into the system and running the script.
ASKER
As above the IP address of the user running the script.
ahh, so
for remote only:
$ who am i | awk -F" " '// { print $4}'
and same for ssh only:
SSH_CLIENT variable is set by OpenSSH server(disable telnet NOW)
for remote only:
$ who am i | awk -F" " '// { print $4}'
and same for ssh only:
SSH_CLIENT variable is set by OpenSSH server(disable telnet NOW)
$ id -p
shows if su has been used...
shows if su has been used...
ASKER
Ok,
That doesnt work cause my server returns a DNS name in the who am i bit, I used to do that.
From your other post I can get the IP address by doing
netstat -n | grep '192.168.1.11.22'
Which shows me the connection on port 22 to the server 192.168.1.11 This returns.
tcp4 0 20 192.168.1.11.22 192.168.1.60.4895 ESTABLISHED
which using your awk example i can do this.
netstat -n | grep '192.168.1.11.22' | awk -F" " '// { print $5}'
which gives me
192.168.1.60.4895
So i'm almost there, have little experience with awk, can you help me with the awk command to pull off the last .4895 bit.
That doesnt work cause my server returns a DNS name in the who am i bit, I used to do that.
From your other post I can get the IP address by doing
netstat -n | grep '192.168.1.11.22'
Which shows me the connection on port 22 to the server 192.168.1.11 This returns.
tcp4 0 20 192.168.1.11.22 192.168.1.60.4895 ESTABLISHED
which using your awk example i can do this.
netstat -n | grep '192.168.1.11.22' | awk -F" " '// { print $5}'
which gives me
192.168.1.60.4895
So i'm almost there, have little experience with awk, can you help me with the awk command to pull off the last .4895 bit.
ASKER
Ok if I add
netstat -n | grep '192.168.1.11.22' | awk -F" " '// { print $5}' -F"." '// {print $1$2$3$4}'
I get the ip address without the .'s ie (192.168.1.60 is shown as 192168160)
netstat -n | grep '192.168.1.11.22' | awk -F" " '// { print $5}' -F"." '// {print $1$2$3$4}'
I get the ip address without the .'s ie (192.168.1.60 is shown as 192168160)
no need for grep:
netstat -n | awk -F" " '/192.168.1.11.22/ { print $5}' -F"." '// {print $1.$2.$3.$4}'
netstat -n | awk -F" " '/192.168.1.11.22/ { print $5}' -F"." '// {print $1.$2.$3.$4}'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
netstat and ifconfig may become useful when combined with awk