Recently, I have a need to list all host names in the LAN (in the SMB protocol), but the findsmb command always fails to list all the host names. I searched the Internet but there was no ready-made solution, so I wrote a python script. The script will scan all IPs in the LAN ARP table and try to resolve their host names, which can list the relevant information more thoroughly. Note that running this script requires the samba-common-bin and arp-scan packages. If you don't have them, please apt install them first. Usage: Run directly or use python3, then enter the name of the network interface to be scanned (if you don’t know, run ifconfig to check, usually ens33, eth0, etc., which appears in the leftmost column of the command output), then press Enter and wait, it may take several minutes to run. Root permissions are required to run! ! #!/usr/bin/env python3 import os def shellrun(cmd): a = os.popen(cmd) b = a.read() c = b.split('\n') return c def cutarpresult(lst): a = [] b = [] for line in lst[2:]: if line != '': a.append(line) else: break for line in a: b.append(line.split('\t')[0]) return b def commandmaker(ip): return 'nmblookup -A ' + ip def getrst(iplist): rst = [] for ip in iplist: rst.append(shellrun(commandmaker(ip))) return rst def washrst(rst): rtn = [] for line in rst: if line[1].split(' ')[1] != 'reply': rtn.append(line[:-1]) return rtn def main(): interface = input('which interface to use: ') iplist = cutarpresult(shellrun('arp-scan -I ' + interface + ' -l')) for rs in washrst(getrst(iplist)): for line in rs: print(line) if __name__ == '__main__': main() This is the end of this article about a script that quickly lists all host names (computer names) in a LAN under Linux. For more information about how to list all host names in a LAN under Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the usage of NULL and NOT NULL when creating tables in MySQL
>>: Detailed explanation of MySQL Innodb storage structure and storage of Null values
This article summarizes the notes for installing ...
When installing in MySQL 8.0.16, some errors may ...
First, let's talk about the in() query. It is...
Table of contents What is MySQL NDB Cluster Preli...
Table of contents Scenario Core Issues Status mon...
Table of contents 1. Open the file Parameter Intr...
Table of contents Preface Introduction to QueryCa...
Although Microsoft provides T4 templates, I find ...
Table of contents Preface zx library $`command` c...
Following the previous article 202 Free High-Qual...
Statistics of QPS values in the last N seconds ...
Connections can be used to query, update, and est...
Regarding the high-performance distributed memory...
Preface In this article, we will use Docker to bu...
Today, I will answer these newbie questions: Build...