Short answer: The most simple thing to do is probably to install on the laptops something like
a dynamic DNS update client to keep track of their dynamic IP address when they are not in your Local Network.
Some words more: The problem is that with only the MAC address you are forced to scan a subnet to find an answering machine with that MAC address once you call it's IP address. Other side of the problem is that this IP change each time the remote machine connects to a provider (or the ADSL reset the connection and assign a different IP address).
It's most simple if that machine (the laptop) communicates somehow the current IP. A way to do it to use a dynamic DNS update client. It exist even a Linux daemon ddclient that help with [dynamic ip servers].(http://ubuntuguide.org/wiki/Dynamic_IP_servers)
After that you choose your name (e.g 'myname.AtFreeOrCommercialProvider.org') and enable on the laptop a program to update the IP, it will be enough to do write from the office the above line to know the current IP of the remote machine:
host myname.AtFreeOrCommercialProvider.org
after you will be able to write it in your script and use as you want.
More words on the original way
The core of your original question is
I know the MAC address of the computer I'm trying to find, I could simply resolve that to an IP, but I'm not sure exactly how I would go about resolving a MAC address to a local IP address on the public network using BASH commands.
To obtain MAC-address from the IP-address you can use,e.g., one of the following method that will give you IP and MAC-address of answering computer in the net:
nbtscan
, e.g.nbtscan 192.168.1.0-255
will scan the IP address group you specify answering with IP address, NetBIOS Name, Server, User, MAC address. (If 192.168.1.xxx is your local network...)
arp
with no mode specifier will print the current content of the IPv4 network neighbour table with IP and MAC address.
From the same family of tools sudo arp-scan --interface=eth0 192.168.0.0/24
if you are using a cable connection, or sudo arp-scan --interface=wlan0 192.168.0.0/24
if you are using a wireless connection...
nmap -sP xxx.xxx.xxx.xxx
on all your local network addresses and filter them with the known MAC addresses.
nmblookup
if you know the NetBIOS names...
After that you have on the same line the IP and the MAC:address you can write your script. Some of this tools may need to be installed.
PS> You can know your current IP address from
# if you are using a cable connection on the network ineterface eth0
sbin/ifconfig eth0 | grep -E "inet:" | awk '{print $2}' | sed s/"inet:"//g
# or you are using a wireless connection on the network ineterface wlan0
sbin/ifconfig wlan0 | grep -E "inet:" | awk '{print $2}' | sed s/"inet:"//g
PPs> IMHO it's not so nice or efficient to scan all internet only to know if that specific computer is connected... It is a different case if you connect this computer to a LAN or a virtual private network (with less IP to be scanned it's possible)... :-)
Hmm, I don't think I was clear. I know how to set up remote access to my own local network already, but in my current scenario, two laptops both connect to the same public network somewhere while traveling. One is mine and the other is my SO's. I want to be able to push a button, detect her IP on the current local network based off of the known MAC address, and then tunnel through to her computer. – Thought Space Designs – 2014-09-07T00:09:17.753
In that case, I have no great answers. You could use arp to find the MAC but that relies on your PC communicating with the other PC first which isn't very reliable. You could use nmap but that relies on doing a ping scan which isn't very friendly and ICMP is usually heavily restricted on public networks. If this was meant for a specific public network you could try setting a static IP on the other PC and hoping no one has it yet. None of these is really very great but they could all do what you want in the right situation. – krowe – 2014-09-07T01:13:25.517
@ThoughtSpaceDesigns See my update for my best answer so far. If I think of something better I'll update again but this shouldn't be too bad (esp if you already use a web drive). – krowe – 2014-09-07T01:24:11.620
Your update does come closer to what I'm trying to achieve, but I'd prefer to not have to use a third computer (server in this case) to act as a liaison. I'd prefer to be able to just find the other computer's IP address based off of the MAC address which I already know. I do have a server connected to the internet that I could do this with, but I'd prefer to make it "direct connect". Any other ideas? – Thought Space Designs – 2014-09-08T14:03:15.193
If you want to connect from the office to a remote computer with a variable IP that changes each time it connects to a provider, the most simple way to do is to know that IP. With mac-address you know the ID of the network adapter and it's challenging to find that MAC address in a wide network. You should know the IP of that computer each time it changes. To do it it's better to install a dynamic DNS client on the remote computer. E.g. you take TSD.noip.org and from the laptop you update with the current IP. From the office with
host TSD.noip.org
it answers you the IP and you can use it. – Hastur – 2014-09-08T19:16:53.267@Hastur He is asking for a way to find the local IP. Dynamic DNS solutions only provide a public IP. This won't work for him because he has no access to the router at his local coffee shop and therefore cannot forward the needed ports through. – krowe – 2014-09-08T19:21:23.863
I don't understand what can he does with the local IP from outside the coffee shop... I suppose he means when he is connected from home or from an hotel. Usually it works. Maybe it's better to connect to a VPN and to scan inside the VPN to search the Ip from the MAC address. (Really not needed at that point because inside the VPN you can chose a fixed local IP for the laptop...)
I think it's time to clean the question... To many comment and the question is migrating to a new one... :) – Hastur – 2014-09-08T19:43:18.577
@Hastur Imagine that he goes to the coffee shop with someone and he and the person he is with both bring a laptop. They are both on the same local network. He just wants the local IP of his friends computer which was assigned by the DHCP server on the coffee shop network. – krowe – 2014-09-08T19:54:33.640
@krowe Gotcha. For this he can easily use
– Hastur – 2014-09-09T07:02:04.167nbtscan
on the local subnet ( orarp
... as answered here) and filter the output withgrep
orawk
. Maybe I should understand it from the question, but it could be easier if he writes informations that should change the meaning of the question in the question itself and not as a comment of an answer...@Hastur Sorry for the ambiguity of my question. I've updated it to be more accurate. Can you please update your answer to match my question? I need something that would work on Ubuntu linux and OSX out of the box with no necessary package installs. Is this possible? – Thought Space Designs – 2014-09-09T22:43:18.777
@ThoughtSpaceDesigns Most Linux distributions don't include either of those packages by default. I doubt OSX does either. Doing this without any additional packages is probably going to be nearly impossible short of writing something from scratch. But they are very common and in most package repositories. – krowe – 2014-09-09T22:52:48.150
Is it possible to install packages via a shell script? I've never had to do that before... – Thought Space Designs – 2014-09-11T15:01:09.627
@ThoughtSpaceDesigns That is possible but why would you? This only needs to be done once on your machine. The reason I'm not suggesting to use those myself is only because I don't think that going onto an open network and doing arp scans is a nice thing to do. It can be detected and it might anger the admin. Aside from that, it is a great option. If you want to be nice, use mine. – krowe – 2014-09-11T15:39:27.137
1Also, start up voting some of these suggestions. Even if you aren't going to use them you should acknowledge that people are trying to help you here. – krowe – 2014-09-11T15:40:39.147
BTW I was talking about using arp above. Using my system you'd need to install a package on all machines you want to have IPs for. Strictly speaking, you could probably read IPs from anywhere without it but you'd need a client (or a tool which acted like one) to upload your IP. You'd also need a cloud storage which you didn't mind sharing with others. The advantage is that there is no scanning, it'll always work if you have access your cloud drive, you will be connecting through the infrastructure of your location (the adhoc approach will be limited to the infrastructure you bring along). – krowe – 2014-09-11T16:01:54.050
I just don't like the idea of having to use a third computer in the chain. I'd prefer to just scout out the one using the information I already know about it. – Thought Space Designs – 2014-09-11T17:16:59.583