Posted: . At: 8:41 PM. This was 5 years ago. Post ID: 13337
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



How to get information about an IP address and who it belongs to.


The nslookup command on UNIX and Linux may be used to get information about an IP address and tell you who it belongs to. This is very useful when using the Internet. This queries the DNS server and can tell you the domain name if any associated with the IP address. Below is an example.

deusexmachina:~ jason$ nslookup 8.8.8.8
Server:		192.168.1.1
Address:	192.168.1.1#53
 
Non-authoritative answer:
8.8.8.8.in-addr.arpa	name = google-public-dns-a.google.com.
 
Authoritative answers can be found from:

To get a comprehensive listing of all IP addresses used by a hostname, use the host command.

deusexmachina:~ jason$ host yahoo.com
yahoo.com has address 98.138.219.231
yahoo.com has address 98.137.246.8
yahoo.com has address 72.30.35.10
yahoo.com has address 98.137.246.7
yahoo.com has address 72.30.35.9
yahoo.com has address 98.138.219.232
yahoo.com has IPv6 address 2001:4998:58:1836::10
yahoo.com has IPv6 address 2001:4998:44:41d::3
yahoo.com has IPv6 address 2001:4998:44:41d::4
yahoo.com has IPv6 address 2001:4998:c:1023::5
yahoo.com has IPv6 address 2001:4998:58:1836::11
yahoo.com has IPv6 address 2001:4998:c:1023::4
yahoo.com mail is handled by 1 mta6.am0.yahoodns.net.
yahoo.com mail is handled by 1 mta7.am0.yahoodns.net.
yahoo.com mail is handled by 1 mta5.am0.yahoodns.net.

If I use the dig command on localhost, it gives me information about the DNS configuration of my home network.

deusexmachina:~ jason$ dig localhost

; <<>> DiG 9.10.6 <<>> localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11539
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
 
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;localhost.			IN	A
 
;; ANSWER SECTION:
localhost.		86400	IN	A	127.0.0.1
 
;; Query time: 25 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Thu Jun 20 20:20:40 AEST 2019
;; MSG SIZE  rcvd: 54

To get a listing of just IP addresses from the ifconfig output, use this syntax.

deusexmachina:~ jason$ ifconfig | grep -Eo '([0-9]{1,3}\.){3}[1-9]\d*'
127.0.0.1
192.168.1.4
192.168.1.255

This is another way to do the same thing.

deusexmachina:~ jason$ ifconfig | grep 'inet ' | cut -d ':' -f 2 | awk '{ print $2 }'
127.0.0.1
192.168.1.4

Another way is to just return the IP address of your machine.

deusexmachina:~ jason$ ifconfig | grep 'inet ' | cut -d ':' -f 2 | awk '{ print $2 }' | grep -E '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'
192.168.1.4

If the machine has more than one IP address, it will return both of them. This one-liner works on Macintosh and PC. So very useful and cross-platform.

4.4 Thu Jun 20 jason@Yog-Sothoth 0: $ ifconfig | grep 'inet ' | cut -d ':' -f 2 | awk '{ print $2 }' | grep -E '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'
192.168.1.5
192.168.122.1

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.