In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "Python how to write nmap scanning tool", the content is detailed, the steps are clear, the details are handled properly, I hope this "Python how to write nmap scanning tool" article can help you solve your doubts, the following follows the editor's ideas slowly in depth, together to learn new knowledge.
NMAP is an open source tool for network detection and security auditing. It can quickly scan the port information exposed by a server. Is a common tool in the field of security testing.
Today, we use python simulation to implement a simple version of the port scanning tool, which mainly uses the socket module. Two methods, connect () and connect_ex (), are provided in the socket module, in which the connect_ex () method has a return value, the return value is a number of int type, the mark is whether the connection is successful, 0 indicates the connection is successful, and other numbers indicate an exception.
Def connect (self, address: Union [_ Address, bytes])-> None:... def connect_ex (self, address: Union [_ Address, bytes])-> int:. First edition:
Def scan_tools_v1 (self): host = input ("Please enter server ip address:") port = int (input ("Please enter port to scan:") sk = socket.socket () sk.settimeout (0.1) conn_result = sk.connect_ex ((host, port)) if conn_result = 0: print ("{} port of server {} is open" .format (host) Port)) else: print ("{} port of server {} is not open" .format (host, port)) sk.close ()
Running result:
D:SoftwarePythonPython39python.exe D:/MyScripts/study_srripts/SockerTools/nmap_tools.py
Please enter the server ip address: 8.129.162.225
Please enter the port to scan: 8080
Port 8080 of server 8.129.162.225 is open
Disadvantages:
1. You can only scan one port at a time
Second Edition: (supports scanning multiple interfaces)
Def scan_tools_v2 (self): host = input ("Please enter server ip address:") ports = input ("Please enter the port range to scan Format 0-0: ") port_start, port_end = ports.split ("-") count = 0 for port in range (int (port_start), int (port_end) + 1): sk = socket.socket () sk.settimeout (65536) conn_result = sk.connect_ex ((host) Port)) if conn_result = = 0: print ("{} port of server {} is open" .format (host, port)) count + = 1 sk.close () if count = = 0: print (f "server {host} {ports} port is not open")
The output result only outputs the information of the open port. If none of the ports in the input port range is open, then the direct output port is not open.
Summary:
1. The above is just a simple version. If you scan all the ports of the server, it will take a long time. Later, you can consider using multithreading technology to optimize it.
2. If the exception input is not checked in the code, it can be optimized.
3. Note that ip is of string type, port is int, initialization of socket object should be placed in the loop, and timeout should be set, otherwise it will take a long time for the default connection to return the result.
Read here, this "Python how to write nmap scanning tool" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.