51

Say that I have two computers connected to the same network. I know that from computer1 and file sharing enabled I can snoop around inside computer2. But say that there is something interesting on computer2, which you access by typing localhost:9091 in safari. (e.g. transmission's web UI). To access that I would have to type in the ip_address_of_computer2:9091 on computer1.

But how do I find out computer2's ip address without using computer2?

  • DO you know computer2's name? – user151019 Apr 9 '13 at 14:23
82

Method #1

The easiest way would be to access your network router's administration page. It will have information about any other devices on the network, including IP address.

Method #2

If you know the computer's network name you can ping it in the Terminal. It will return the computer's IP address.

Method #3

If you don't know the computer's network name, there's another trick you can do using ping. Find your IP address and your subnet mask. Both should be visible in the Network preference pane of System Preferences. Line up your IP address and your subnet mask, and replace any 0 values in the subnet mask with 255 in the same relative position of the IP address. For example, if you have the following IP address and subnet mask, respectively:

192.168.1.151

255.255.255.0

The 0 is in the last field of the subnet mask, so you replace the last field of the IP address with 255 and ping it: ping 192.168.1.255

You should get a response with the IP address of any device on the network capable of responding to pings.

Method #4

Last trick is to use the terminal command arp -a. This will show the IP and MAC address of all devices on the network that it knows about.

Last two tricks courtesy of this Macworld article.

  • 8
    Method # 4 arp -a will work if, and only if, the Mac already successfully probed or was connected to a host. Try yourself by restarting your Mac and displaying the arp table. It will be almost empty. To populate that table you need to run something like a ping scan: nmap -sP 192.168.1.0/24 – ripat Feb 26 '14 at 14:12
  • For some reason, pinging 192.168.1.255 returns the addresses from all Macs in the network, but none from the Linux machines ?!? Great tip though! – ssc Mar 7 '14 at 20:57
  • 1
    ping SOME-PC -4 to forve the IPV4 resolving. – Nakilon Aug 3 '14 at 6:13
  • Does this work if your are pinging a windows computer? – Cullub Jan 26 '15 at 18:16
  • 1
    @cullub Yes, it works in windows. ping adminPC pings the adminPC computer and displays the IP address. And as Nakilon commented, ping adminPC -4 displays the IPv4. – Lucky Aug 22 '16 at 7:42
19

Type the command

  arp -a

This will show you all connections one by one.

  • This doesn't seem to work for some devices. I'm not sure if it's because the devices aren't "listening" or if it's because of different OS's but I'm trying it now and arp -a is not picking up one of my linux boxes. – Jacksonkr Apr 12 '16 at 13:51
  • The first time you go to talk to another device on your computer, your computer needs to resolve IP -> MAC, and so it broadcasts "who has IP xxx.yyy.zzz.aaa?", and the owner of that IP responds (broadcasts) with "me!", and of course that packet has a source MAC in it. If that transaction hasn't taken place while your device was on the network, it won't have an ARP entry for it. Hence: not all devices show up in the ARP table, but may show up in other devices' ARP tables. – Harv Apr 7 '17 at 7:44
4

Q: How do I know the IP addresses of other computers in my network?

A lot of networks

Well, first of all your computer is probably on a lot of networks. You can see this with the ifconfig command. There is a lot of info in there, but most of it is overwhelming, so I like to filter is like so:

$ ifconfig | grep -E '^[a-z0-9]|inet '

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet 192.168.0.101 netmask 0xffffff00 broadcast 192.168.0.255
en1: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
en2: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500
    inet 172.141.0.10 --> 172.141.0.9 netmask 0xffffffff
en5: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    inet 169.254.146.193 netmask 0xffff0000 broadcast 169.254.255.255
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet 192.168.3.1 netmask 0xffffff00 broadcast 192.168.3.255

The first field of the left aligned lines are network interface names. You wifi is probably en0. My TunnelBlick VPN to AWS is utun1. My System Preferences > Sharing > Internet Sharing created bridge100 for the RaspberryPi I have getting internet from my MacBook Pro via my ethernet dongle.

Assume IPv4

Because you asked for IP addresses I assume IPv4 addresses are what you care about. I used "inet " (with a space) to block the "inet6" entries for IPv6. If you wanted IPv6 you probably know more about networking than I do and I should be asking you questions.

Find the hosts

Let's focus on that bridge100 and bring you a little Google traffic. Lots of people run into this situation when they want to SSH or RDC into a headless computer (like a RaspberryPi) either on their network or tethered via Internet Sharing. It's especially difficult when you have no connection history (arp table) with the device. For this you can use sudo nmap -sn 192.168.3.0/24, which is the value of bridge100 inet (192.168.3.1) with the last digit replaced with "0/24". However, nmap isn't standard on OSX so we can install it with homebrew.

$ brew install nmap
Warning: nmap-7.31 already installed

$ sudo nmap -sn 192.168.3.0/24
Password:

Starting Nmap 7.31 ( https://nmap.org ) at 2016-11-21 22:03 EST
Nmap scan report for 192.168.3.6
Host is up (0.00025s latency).
Nmap scan report for 192.168.3.1
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.08 seconds

From that you can assume that my RaspberyPi got IP 192.168.3.6 for some reason. Last time I connected it I was on a different subnet and it got 192.168.2.3. That nmap trick is a lot better than typingping 192.168.3.2 ... ping 192.168.3.6 until you find it.

I hope that helps.

3

There are a few other tools that have not been mentioned yet for discovering IP address information, assuming you have the host name and you are using mDNS (aka Bonjour in Mac environments). Unless you have configured things differently, your local network names are in the form host-name.local so in your initial example you would be looking for computer2.local

The first:

    dscacheutil -q host -a name <host-name>.local

For example:

    % dscacheutil -q host -a name computer2.local
    name: computer2.local
    ip_address: 10.0.1.6

Another useful tool is dig (try dig google.com for example), which with a few special parameters can be used to query the mDNS nodes of your local network.

    % dig @224.0.0.251 -p 5353 <host-name>.local
    % dig @224.0.0.251 -p 5353 -x <ip-address>

To get just the IP address out of dig you can try:

    % dig +short @224.0.0.251 -p 5353 <host-name>.local
  • Good one bu it requires to know the IP address or computer multicastDNS name (.local). – Florian Bidabe Oct 18 '14 at 22:42
  • BonjourBrowser is a nice GUI application for this. – Florian Bidabe Oct 18 '14 at 22:43
  • @FlorianBidabe - Why do you say you need to know the IP address to use these commands? These commands return the IP address of the named machine. Yes, it is required to know the name of the target machine to use this method. – KenB Oct 22 '14 at 6:25
3

This script should give you what you are looking for really quickly and requires to have nmap installed. The advantage is that if your host does not reply to ping probes, nmap would still find the host while other tools will not.

#!/bin/bash
i="en1" # edit this to fit your Network interface
cidr=$(while read y; do echo ${y%.*}".0/$(m=0; while read -n 1 x && [ $x = f ]; do m=$[m+4]; done < <(ifconfig $i | awk '/mask/             {$4=substr($4,3); print $4}'); echo $m )"; done < <(ifconfig $i | awk '/inet[ ]/{print $2}') | head -n 1 | sed s/addr://g | sed 's/\/0//g')
myip=`ifconfig $i | grep "inet " | awk 'NR==1 {print $2}' | sed s/addr://g`
set -x
sudo nmap -n -T4 -PN -p9091 --exclude "$myip" "$cidr"

Store this script as lookup.sh and call it (with switch to english) with

LANG=c bash lookup.sh
  • How do you save and run that? – Daniel Pendergast Oct 14 '14 at 15:08
  • You paste this in TextEditor, and save and name this file "qnmap". You then move this file to /usr/bin (Hold Command+Shift+G, or Finder / Go / Go to folder : /usr/bin). open terminal, type "sudo chmod a+x /usr/bin/qnmap". Type "qnmap" in the terminal and wait for the result. – Florian Bidabe Oct 15 '14 at 2:48
  • Ok. I get this error: /usr/bin/qnmap: line 2: =en1: command not found It looks like the dollar sign before the i shouldn't be there. – Daniel Pendergast Oct 15 '14 at 12:51
  • 1
    Sorry Dan, my bad, the line should be : i="en1" – Florian Bidabe Oct 16 '14 at 3:20
  • Cool. It works good. – Daniel Pendergast Oct 17 '14 at 16:14
2

You could also use netstat to show network addresses:

roger.moore@WKSTCAL0141 ~
$ netstat -n

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    127.0.0.1:11235        127.0.0.1:49184        ESTABLISHED
  TCP    127.0.0.1:49155        127.0.0.1:49156        ESTABLISHED
  TCP    127.0.0.1:49156        127.0.0.1:49155        ESTABLISHED
  TCP    127.0.0.1:49184        127.0.0.1:11235        ESTABLISHED
  TCP    192.168.10.131:445     192.168.10.119:52624   ESTABLISHED
  TCP    192.168.10.131:1433    192.168.10.2:60866     ESTABLISHED
  TCP    192.168.10.131:1433    192.168.10.119:52775   ESTABLISHED
  TCP    192.168.10.131:3389    192.168.10.119:54473   ESTABLISHED
  TCP    192.168.10.131:49154   192.168.10.119:52796   ESTABLISHED
  TCP    192.168.10.131:49182   192.168.10.9:52230     ESTABLISHED
  TCP    192.168.10.131:49247   192.168.10.6:445       ESTABLISHED
  TCP    192.168.10.131:49432   192.168.10.4:1106      ESTABLISHED
  TCP    192.168.10.131:49440   192.168.10.4:1106      ESTABLISHED
  TCP    192.168.10.131:49451   192.168.10.6:1025      ESTABLISHED
  TCP    192.168.10.131:55100   192.168.10.2:445       ESTABLISHED
  TCP    192.168.10.131:64558   192.168.10.20:135      TIME_WAIT
  TCP    192.168.10.131:64559   192.168.10.20:49158    TIME_WAIT
  TCP    192.168.10.131:64566   192.168.10.100:135     TIME_WAIT
  TCP    192.168.10.131:64575   192.168.10.100:59811   TIME_WAIT
  TCP    192.168.10.131:64581   192.168.10.41:139      TIME_WAIT
  TCP    192.168.10.131:64582   192.168.10.3:5357      TIME_WAIT
  TCP    192.168.10.131:64585   192.168.10.61:3910     TIME_WAIT
  TCP    192.168.10.131:64587   192.168.10.65:3910     TIME_WAIT
  TCP    192.168.10.131:64588   192.168.10.9:139       TIME_WAIT
  TCP    192.168.10.131:64589   192.168.10.135:2869    ESTABLISHED
  TCP    192.168.10.131:64593   192.168.10.6:135       TIME_WAIT
  TCP    192.168.10.131:64594   192.168.10.6:1025      TIME_WAIT
  TCP    192.168.10.131:64599   192.168.10.100:59811   TIME_WAIT
0

If you want to know the name using IP: http://runakay.blogspot.com/2013/12/obtaining-computer-name-from-ip-address.html

  • 1
    Welcome to Ask Different! While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – grg Dec 28 '13 at 22:59
0

You can install Wireshark and start a scan on your network card.

Filter the result by "nbns", and you will see the IP address in the upper window.

You must log in to answer this question.

protected by Community Mar 16 '14 at 6:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .