Getting information about an IP address on Linux is very easy. You may get the geographical location and other useful information. Although for an Internet IP address of a person, this is the location of the ISP and not the location of the router belonging to the person.
Get the geographical location of an IP address. This is using the ipcalc utility.
[root@localhost jcartwright]# ipcalc -g 119.15.100.252 COUNTRYCODE=AU COUNTRY=Australia COORDINATES="-35.274700,149.135300" |
Get the network prefix of the IP address.
[root@localhost jcartwright]# ipcalc -p 119.15.100.252 PREFIX=32 |
Print all information about the IP address.
[root@localhost jcartwright]# ipcalc --all-info 119.15.100.252 Address: 119.15.100.252 Reverse DNS: 252.100.15.119.in-addr.arpa. Address space: Internet Address class: Class A Country code: AU Country: Australia Coordinates: -35.274700,149.135300 |
And this is how to get all information about your current IP address on your LAN.
(jcartwright@localhost) 192.168.1.5 ~ $ ipcalc --all-info `ip a | awk 'NR==10{print $2}'` Address: 192.168.1.5 Network: 192.168.1.0/24 Netmask: 255.255.255.0 = 24 Broadcast: 192.168.1.255 Reverse DNS: 1.168.192.in-addr.arpa. Address space: Private Use Address class: Class C HostMin: 192.168.1.1 HostMax: 192.168.1.254 Hosts/Net: 254 |
This command will get your current IP address.
ip a | awk 'NR==10{print $2}' |
Then, placing the command in backticks allows it to be a parameter for another command.
ipcalc --all-info `ip a | awk 'NR==10{print $2}'` |
The nmap utility may also be used to print information about a host and any open ports.
(jcartwright@localhost) 192.168.1.5 ~ $ nmap 192.168.1.0/24 Starting Nmap 7.91 ( https://nmap.org ) at 2023-08-04 09:39 AEST Nmap scan report for 192.168.1.1 Host is up (0.00067s latency). Not shown: 996 filtered ports PORT STATE SERVICE 53/tcp open domain 80/tcp open http 443/tcp open https 5060/tcp open sip Nmap scan report for 192.168.1.3 Host is up (0.0041s latency). All 1000 scanned ports on 192.168.1.3 are closed Nmap scan report for 192.168.1.5 Host is up (0.00011s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 111/tcp open rpcbind Nmap done: 256 IP addresses (3 hosts up) scanned in 24.34 seconds |
And this is how to scan for just a few ports on Linux with nmap.
[root@localhost jcartwright]# nmap -sN -p 22,25,80,443 192.168.1.0/24 Starting Nmap 7.91 ( https://nmap.org ) at 2023-08-04 09:45 AEST Nmap scan report for 192.168.1.1 Host is up (0.00038s latency). PORT STATE SERVICE 22/tcp open|filtered ssh 25/tcp open|filtered smtp 80/tcp open|filtered http 443/tcp open|filtered https MAC Address: C8:14:51:5F:A9:47 (Huawei Technologies) Nmap scan report for 192.168.1.3 Host is up (0.31s latency). PORT STATE SERVICE 22/tcp closed ssh 25/tcp closed smtp 80/tcp closed http 443/tcp closed https MAC Address: EA:F0:F2:61:30:2E (Unknown) Nmap scan report for 192.168.1.5 Host is up. PORT STATE SERVICE 22/tcp open|filtered ssh 25/tcp open|filtered smtp 80/tcp open|filtered http 443/tcp open|filtered https Nmap done: 256 IP addresses (3 hosts up) scanned in 9.12 seconds |