How can I issue a nmap command that shows me all the alive machines' IP addresses and corresponding hostname s in the LAN that I am connected? (if this can be done in another way/tool you surely are welcome to answer)
How can I issue a nmap command that shows me all the alive machines' IP addresses and corresponding hostname s in the LAN that I am connected? (if this can be done in another way/tool you surely are welcome to answer)
nmap versions lower than 5.30BETA1:
newer nmap versions:
This gives me hostnames along with IP adresses, and only pings the hosts to discover them. This will only give you the hostnames if you run it as
root
.EDIT: As of Nmap 5.30BETA1 [2010-03-29]
-sP
has been replaced with-sn
as the preferred way to do ping scans, while skipping port scanning, just like the comments indicate:Note that name resolution is only as good as the reverse-dns population is. Also note that this won't get you systems which are firewalled against ping (which practically every windows workstation is by default).
If you are local to the systems (ie on the same subnet) you can do something like
...but weird things happen to me sometimes when I wrap arping up in a loop. Also you have to do the lookup yourself, with something like
You can scan an entire subnet, can use wildcards also.
or
NMAP will return the 'reverse-lookup' of the IP address in question, it can't return the forward lookup address. Or addresses in the case of Web Servers doing name-based virtual hosting. Nmap isn't the tool for this.
nmap -sP 192.168.0.0/24 will output something like :
You can use the following command :
You can simply use
arp
command like this:Best and Fastest way to ping all Ips in Local Net is by disabling DNS reverse Resolution
Use :
NMAP -sn 192.168.1.1-255
this will scan all 255 hosts in IP range 192.168.1.1 - 192.168.1.255
If you want a easily parse-able file
Use :
NMAP -sn -oG Name.txt 192.168.1.1-255
Since there is no given IP for the LAN we could assume it is 192.168 but that's not always the case, so the first thing is to discover our IP address and our subnet mask.
use ifconfig for this and use regexp to clean the results
Now assuming your Ip is 192.168.0.100 and your mask is 255.255.255.0 then you can scan 1-254 like so
to see hostnames and MAC addresses also, then run this as root otherwise all the scans will run as a non-privileged user and all scans will have to do a TCP Connect (complete 3-way handshake) to get something. As root, you run Syn and don't have to finish the 3-way handshake.
This is basically what you need to answer your question and get what you wanted. There is a wealth of parameters but each serves a special purpose.
----edit
I've just noticed hostname. You can use a service discovery scan since it will execute several scripts(one of which is nbstat.nse) and will return hostnames. Don't expect to get the hostnames of all the machines that you scan.
or you can just run the specific nbstat.nse script and gain time and effort.
nbstat.nse uses UDP port 137. In some cases you might also get the hostname from SNMP using the snmp-interfaces script but that will require UDP port 161 to be open.
I think you should run this: