1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How to determine remote host IP for SSH session

Discussion in 'Linux and Unix' started by dmmiller2k, Apr 8, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. dmmiller2k

    dmmiller2k Thread Starter

    Joined:
    Jun 28, 2007
    Messages:
    4
    If I ssh into a NetBSD machine and get a [bash] shell prompt, how do I find out my remote IP address?

    When I ssh in from work, I go through our proxy server, so I don't really know the external IP address I appear to be connecting from.

    Some UNIX-like systems I've used displayed this in the output to the, 'finger username' command,

    $ finger `whoami`
    Login: XXX Name: Xavier X. Xylophone
    Directory: /arpa/xz/x/xxx Shell: /usr/pkg/bin/bash
    Last login Tue Apr 8 15:12 (UTC) from 1.2.3.4:5 on ttyrp
    Mail last read Tue Apr 8 15:06 2008 (UTC)
    Mail forwarded to: "|IFS=' '&&exec /usr/pkg/bin/procmail -f-||exit 75 #xxx"
    No Plan.

    but on one particular [NetBSD] system, it only shows me the tty I am using:

    $ finger `whoami`
    Login: XXX Name: Xavier X. Xylophone
    Directory: /arpa/xz/x/xxx Shell: /usr/pkg/bin/bash
    Last login Tue Apr 8 15:12 (UTC) on ttyrp
    Mail last read Tue Apr 8 15:06 2008 (UTC)
    Mail forwarded to: "|IFS=' '&&exec /usr/pkg/bin/procmail -f-||exit 75 #xxx"
    No Plan.

    How do I query the remote address, given an active tty, e.g. 'ttyrp'?

    Thanks,
    David
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi David,

    Try the command ifconfig to see what results are printed out on your terminal screen and look for inet address or where P-t-P (for dialup on ppp0 or some other identifier for eth0 if not on dialup connection) is followed by the remote ip address.

    Also, run ifconfig locally to see what you get. Use ipconfig for Windows if that is your local computer.

    -- Tom
     
  3. dmmiller2k

    dmmiller2k Thread Starter

    Joined:
    Jun 28, 2007
    Messages:
    4
    Thanks, but the ifconfig command only shows the IP addresses of the local machine's network adapters, not the remote IP address connected to my tty, say, 'ttyp0'.

    If I run the finger command with no parameters and grep for my username, I get something like this:

    $ finger | fgrep `whoami`
    xxx Xavier X. Xylophone p0 - Thu 18:24

    which shows that I am using the tty named, 'ttyp0'. Now, I would like to see the remote IP address of the host connected to 'ttyp0'. Isn't there a way to do this?
     
  4. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Can you issue the ifconfig command while logged into the remote machine - you should not be getting local ip addresses at a remote location.

    -- Tom
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Which freeshell server are you logging in to directly and why aren't you just using the Round Robin tty address?

    Do you want to know your Public IP addrress. You can go to whatismyip.com for that.

    I thought he had lastlog installed. I can get the man page for it but when I try to execute it, it tells me it can't be found. So maybe he doesn't want anyone using that.
     
  6. fenderfreek

    fenderfreek

    Joined:
    Mar 14, 2006
    Messages:
    201
    I understand what you're going for, but the closest suggestion I can toss in is to check the output of the "last" command, or the "who" command. The output will show your hostname. Here's a little one-liner I threw together and tested real quick that may give you what you need, assuming your IP can be resolved to a hostname. If it doesn't behave as expected, you can just look at the output of one of those commands and grep it by hand.;)

    Code:
    % nslookup `who | grep *username* | sed 's/.*(\(.*\)).*/\1/g'`
    Server:  ns4.ncsu.edu   <-Ignore these two lines. They are just about the NS
    Address:  152.1.1.161
    
    Name:    myhostname.ncsu.edu  <- This should be your hostname (FQDN)
    Address:  152.7.7.123  <- This should be your IP
    
    Just put your username in the appropriate spot, and try it out. I ran this on a Solaris box, so you *might* need to tweak it for a BSD system.
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/701608

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice