6

Is that possible to get the IP address of my machine from the hostname or the machine's own mac address?

If yes, how? If not, could you suggest an alternative way?

Seth
  • 57,282
  • 43
  • 144
  • 200
Fahadkalis
  • 161
  • 1
  • 1
  • 4
  • 2
    Of your system or a remote system? – muru Feb 13 '15 at 23:06
  • right now I want to do for my system but later I need for remote system as well – Fahadkalis Feb 13 '15 at 23:09
  • 4
    I'm not sure exactly what you're trying to accomplish, but the `hostname --all-ip-addresses` command relates the hostname to IPs, `nslookup` and `dig` can be used for general DNS resolving and the `arp -na` command can list all IPs and MAC addresses in the local network that you have connected to at some point. – muru Feb 13 '15 at 23:15
  • 1
    ping -c1 hostname – Panther Feb 13 '15 at 23:24
  • @muru sorry I want to know remote machine ip address by hostname or mac-address.... basically that machine is raspberrypi – Fahadkalis Feb 13 '15 at 23:29
  • 1
    @muru is correct. If the machine is one hop away, `arp` will help you find the IP from the MAC address. `nmap` or `zenmap` can also be helpful to identify machines on your network – noleti Feb 13 '15 at 23:32
  • 1
    In addition to @noleti's suggestion: http://superuser.com/q/261818/334516 – muru Feb 13 '15 at 23:33
  • Or http://askubuntu.com/questions/57277/how-do-i-access-machines-on-the-home-network-with-their-machine-name – muru Feb 13 '15 at 23:35
  • @muru let suppose if my mac address is `abcdef` then how can i find my ip address through `arp` or `nmap` or `zenmap` – Fahadkalis Feb 13 '15 at 23:40
  • @Fahadkalis: Run `arp -n`, will will get the mappings.. – heemayl Feb 14 '15 at 01:51

2 Answers2

5

Of all the suggestions in the comments this one seems easiest.

sudo apt-get install arp-scan

sudo arp-scan --interface=wlan0 --localnet where wlan0 is your interface if your on a wire you'll likely change wlan0 to eth0. You can find out your interface with ifconfig you'll get output similar to this that provides The IP and MAC Address of each machine on your local subnet.

$ sudo arp-scan --interface=eth0 --localnet
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.15.2    XX:XX:XX:XX:XX:XX   NETGEAR
192.168.15.24   XX:XX:XX:XX:XX:XX   BROTHER INDUSTRIES, LTD.
192.168.15.103  XX:XX:XX:XX:XX:XX   GIGA-BYTE TECHNOLOGY CO.,LTD.

Sources:

1) http://www.binarytides.com/scan-the-local-network-with-arp-scan-on-ubuntu/

2) https://superuser.com/questions/261818/how-can-i-list-all-ips-in-the-connected-network-through-terminal-preferably

3)Experience

Elder Geek
  • 35,476
  • 25
  • 95
  • 181
0

Technically it is possibly but Logically not. We can get IP by pinging hostname only if it is bind to that certain IP. In local host its hosts file do that work on business network it's DNS which do that work & on internet as well it's DNS but A records/cname which do that work. We can also get IPs assigned ot hostname set for particular MAC id, but that programatically possible not sure if you can do that with simple commands

To know what is your public IP address : www.ipconfig.in

Edit:

getent hosts <hostname> | awk

This works locally aswell.

An0n
  • 2,049
  • 1
  • 11
  • 27
Bella
  • 21
  • 2