Results 1 to 8 of 8

Thread: finding IP address of computer that is ssh'd into server

  1. #1
    Join Date
    May 2011
    Beans
    196

    finding IP address of computer that is ssh'd into server

    Hello folks, so i am sshing into a ubuntu server (this server is just for me to mess around in)

    is there a command i can run on the server that will show the IP address of the computer that is currently SSHed into the server.?


    if you need me to explain a little more let me know.
    Fail Fail Fail SUCCESS Fail Fail Fail

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,899
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: finding IP address of computer that is ssh'd into server

    Hi hookitup.

    This could help:
    Code:
    who --ips
    Let us know how it goes.
    Regards.

  3. #3
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: finding IP address of computer that is ssh'd into server

    I'm partial myself to the 'w' command, that gives a little more information. Literally just type 'w' in the terminal and you'll get info on who's logged in, their IP address, when they logged in, and what they're doing currently.

  4. #4
    Join Date
    May 2011
    Beans
    196

    Re: finding IP address of computer that is ssh'd into server

    great thanks folks.
    Fail Fail Fail SUCCESS Fail Fail Fail

  5. #5
    Join Date
    Sep 2006
    Beans
    7,625
    Distro
    Lubuntu Development Release

    Re: finding IP address of computer that is ssh'd into server

    So you have yet another choice, you can also look the output of last.

    Code:
    last -n 5
    For your own ssh session you can look at the variables $SSH_CLIENT and $SSH_CONNECTION. Those will give you the port numbers too but will include the ip number.
    Last edited by Lars Noodén; November 7th, 2012 at 10:22 AM. Reason: typo

  6. #6
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,899
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: finding IP address of computer that is ssh'd into server

    Just to be a little more precise

    If you have a well setup dhcp/dns server combo, all these commands ('who', 'w' and 'last') will report by default the hostname of the remote host (using reverse lookup).

    For instance, they'll show something like:
    Code:
    remote_host_name.localnet
    You can explicitly ask both 'who' and 'last' to show ip addresses by using additional options:
    Code:
    who --ips
    
    last -5i
    Best Regards.

  7. #7
    Join Date
    May 2011
    Beans
    196

    Re: finding IP address of computer that is ssh'd into server

    Papib

    so what your saying is i can possible have it displace the IP address and hostname of the user remoting in?
    Fail Fail Fail SUCCESS Fail Fail Fail

  8. #8
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,899
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: finding IP address of computer that is ssh'd into server

    If you are scripting, you should be careful.

    For instance, this are the results on my server (assuming just one user).

    With no options:
    Code:
    $ who  | awk '{print $NF}'
    (vaughan.localnet)
    However, with options:
    Code:
    $ who --ips | awk '{print $NF}'
    192.168.1.101

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •