Operating System - HP-UX
1837409 Members
3611 Online
110116 Solutions
New Discussion

Re: HPUX11.11 telnet connection, addressed ip-number on host

 
SOLVED
Go to solution

HPUX11.11 telnet connection, addressed ip-number on host

I want to divert in login-script to different applications dependent on the incoming network port (ip-address) of the telnet sessions.
we run some applications on a rp5470 and want to start an application depending on the chosen incoming ip-address of the host.

How can I check from which incoming host ip address the user session started.

Any ideas welcome
sfra
12 REPLIES 12
Pieter_5
Advisor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hi,

Who -um creates an output with username and ip-adress for the current session.

who -um | awk '{ print $7'} prints the ip-adress for the current session.

Robert-Jan Goossens
Honored Contributor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hello,

something like this in your .profile.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x25f338bcbbbb2b478d68632760cdba9f,00.html

Hope it helps,

Robert-Jan.
Kevin O'Donovan
Regular Advisor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hi,

I guess you're putting this into the .profile/.login/.cshrc file of the user?

You could possibly do something with who -R? That usually tells you what machine a particular user is logged in from. However it would complicate things a bit if there are multiple users logged in with the same userid similtaneously, you'd have to work out which telnet session you're on and pick out the entry from who -R with that. Use cut to pick out a particular field or fields of the who -R output.

Not sure whether whoami outputs the tty, have an idea it does but can't quite picture the output and don't have access to a HPUX box just now.

If you sort that out you could put a case statement into the .login/.cshrc/.profile that would start the application depending on the IP address it got from the who -R command.

Hope that helps?
Kevin.
twang
Honored Contributor

Re: HPUX11.11 telnet connection, addressed ip-number on host

You can see who logining using:
# who u
or, see who login as a particular user:
# finger root

Re: HPUX11.11 telnet connection, addressed ip-number on host

maybe I was not quite accurate in the formulation of my question.
I do not wnt to know where from (client ip address) somebody wants to connect, but to what ip-address on the host they connect.

who -u or -R ... gives me the source ip address of the client.

we have some network ports (4-port network card) where we assigned different ip-adresses to it.

Now I want to know, via which host-ipaddress the client is comming in.
This makes it possible to give the users one icon (~ destinatin ipaddress) per application on their desktop. (some users have to use more than one application on this host)
sfra
Zigor Buruaga
Esteemed Contributor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hi,

Once you get the client IP address ( as suggested before ), you can run "netstat -a | grep client_IP" and look for the Ip of your hosts ( IP or alias of that lan card ).

Hope this helps.
Regards,
Zigor
Ron Kinner
Honored Contributor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Zigor is close but it needs to be netstat -an if you want to see the IP addresses otherwise you get names. -an is a lot faster anyway since it doesn't have to do a reverse DNS on each IP address.

Ron

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hello
Zigor and Ron are very close, but I cannot distinquish between 2 or more connections from one client (e.g. 2 different applications or 2 sessions, same application).

the only clue may be the not empty send-Q of netstat -an e.g. the output of the following statement:
netstat -an |grep $(who -um | awk '{ print $8}')
tcp 0 2 193.81.97.5.23 193.228.206.84.1803 ESTABLISHED
tcp 0 0 192.46.193.163.23 193.228.206.84.4645 ESTABLISHED
tcp 0 0 192.46.193.163.23 193.228.206.84.1678 ESTABLISHED

see parameter 3 (2) in 1??st line.
but this may not be the only active send-Q from one client?
sfra
Zigor Buruaga
Esteemed Contributor

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hi,

Ron, thanks for the correction.
Franz, maybe I still not understand the question, but I think you can distinguish between connections from one client.

tcp 0 2 193.81.97.5.23 193.228.206.84.1803 ESTABLISHED
tcp 0 0 192.46.193.163.23 193.228.206.84.4645 ESTABLISHED
tcp 0 0 192.46.193.163.23 193.228.206.84.1678 ESTABLISHED

In the netstat output you can see that the client with IP 193.228.206.84 has three telnet sessions established, two of them against server IP 192.46.193.163 and one against server IP 193.81.97.5.
So, I think you need to use the TCP port used by the client to distinguish between the connections. Suppose that you have no connections from the client i.e 193.228.206.xxx, you can edit the .profile and put the necessary lines to get the client IP, server IP used, TCP port used by the client, and terminal used by client ( TERMI=`who -um | awk '{ print $2}'`. You can store all that info in a line in a temp file. In this way, when the same client connects again ( now there are two sessions ) you only need to search in that "log" file to distinguish between connections from the same client ( now you know which is the previous connection ).
Finally, you can edit the .logout file and put the necessary lines to clean the "log" file when a user disconnects ( i.e looking for the terminal used ).
It??s only an idea ( perhaps little complicated ), and I have no tested ... maybe this is a piece of nonsense ;-)

Kind regards,
Zigor


Darren Besler
New Member
Solution

Re: HPUX11.11 telnet connection, addressed ip-number on host

I have done this. That is, use multiple virtual IP addresses on a server, and then in /etc/profile, load different environments, etc based on the target IP address of the connection. This works for telnet and ssh.

1. Its easy with ssh as, sshd sets an env var "SSH_CLIENT" which includes the tcp port numbers (src,dest) which can be used with netstat -na output to determine the dest IP address.

2. For telnet, it was a bit harder. Once inside the /etc/profile, there is no direct network information available as the session has been handed off to a pseudo tty which passes data back and forth with the telnetd spawned for the session.

What I did was use the open soruce tcp wrappers code to wrap telnetd spawns from inetd. Now, the actual code was modified to collect the dest IP address from sockaddr structure representing the connection and dump it to a tmp file keyed by pid. Later, in /etc/profile, this file is found via the sh's PPID. The information is collected at the end of function sock_host in module socket.c.

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hello,

Zigor, thank you for the input. But there is the problem of assigning the right address.port number to the actual telnet connection. The missing link for me is the connection of the port# and the device telnet is assigned to. At least I could get no reliable result with:
netstat -an |grep $(who -um | awk '{ print $8}')| awk ' { if ($3 != "0") {print $4} } '| awk '{ FS="."; { print $1"."$2"."$3"."$4 }}'

But maybe I just got the hint.
I am trying lsof, a HP-utility, that seems to be somewhat in the direction Darren had solved his Problem.
Darren, this lsof seems to be my "missing link". Here I should get the process-id of the current telnet process, the client-ip and host-incoming-ip.

I will post, if this solution works.
Kind regards,
Franz
sfra

Re: HPUX11.11 telnet connection, addressed ip-number on host

Hello

my solution for this problem is with lsof, list open files.
get process number of current telnet session
grep $(ps |grep telnetd | awk '{ print $2 }')
as search criteria for grep on lsof output, and formatting with awk for getting the dest. address we looked for.

sample script see below

...........
# check welche Host-IP-Adresse adressiert wurde
ZIELA="$(lsof -i -n | grep $(ps |grep telnetd | awk '{ print $2 }')|awk '{ if ( NR == 1) print $9 }' | awk '{ FS=":"; { print $1}}')"

GR=`groups`
echo $ZIELA $GR

case ${ZIELA} in
"199.43.177.148" )

if [ -n `echo $GR |grep proalpha` ]
then
echo "ILS wurde gewaehlt"
SYST=ILS; echo $SYST
### . /home/prof/.usprofile
fi
;;
"*" )
echo "NIX wurde gewaehlt $ZIELA"
exit
;;
esac # case ZIELA
...........

Thank you for your help
Franz
sfra