Reverse Lookup of NetBIOS Name
If you are a network administrator or must work with large Windows user, you may want to obtain the netbios name of each machine programmatically. Why? There are many reasons to know netbios name by given IP address.
- Create a list of IP and associate name
- Find name conflict
- Obtain machine information from IP
Fortunately, samba package provides a tool called "nmblookup" to help us in this situation. It is very easy to reverse lookup the name using option "-A". However, there are lots of information returned.
[sugree@magi1 admintools]$ nmblookup -A 158.108.34.56 Looking up status of 158.108.34.56 VIKRIT <00> - M WORKGROUP <00> - M VIKRIT <20> - M WORKGROUP <1e> - M MAC Address = 00-C0-9F-60-C9-E2
Then we should easily get the name using awk. As a result, I wrote a script namely "ip2nb.sh" as follow.
#!/bin/sh IP=$1 nmblookup -A $IP | awk '/<20>/ { print tolower($1) }'
So I can obtain name of 158.108.34.56 in just one command.
[sugree@magi1 admintools]$ ./ip2nb.sh 158.108.34.56 vikrit
- sugree's blog
- 1893 reads
Very cool
single quote
Post new comment