Back to Browse

Introduction to Nmap Scanner & Module with Python code | Complete Tutorial

1.1K views
Sep 21, 2023
1:12:53

Introduction to Nmap Scanner & Module with Python code Nmap, or Network Mapper, is a free and open-source network scanning tool that is used to discover hosts and services on a network. It can also be used to determine operating system and application versions, as well as to identify security vulnerabilities. The nmap module for Python allows you to use Nmap functionality from within your Python scripts. This can be useful for automating tasks such as network discovery, vulnerability scanning, and penetration testing. In this video, you will learn how to use the nmap module in Python to scan a network for open ports and services. You will also learn how to parse the scan results and print them to the console. *Examples* The following is a simple Python script that uses the nmap module to scan a network for open ports and services: import nmap # Create a new Nmap PortScanner object scanner = nmap.PortScanner() # Scan the network for open ports and services on the specified IP address scanner.scan('192.168.1.100') # Print the scan results to the console for host in scanner.all_hosts(): print('Host : %s (%s)' % (host, scanner[host].hostname())) print('State : %s' % scanner[host].state()) for port in scanner[host].all_tcp_ports(): print('Port : %d (open)' % port) The following is an example of how to parse the scan results and print them to a file: import nmap import csv # Create a new Nmap PortScanner object scanner = nmap.PortScanner() # Scan the network for open ports and services on the specified IP address scanner.scan('192.168.1.100') # Open a CSV file for writing with open('scan_results.csv', 'w', newline='') as f: writer = csv.writer(f) # Write the header row writer.writerow(['Host', 'State', 'Port']) # Iterate over the scan results and write each row to the CSV file for host in scanner.all_hosts(): writer.writerow([host, scanner[host].state(), scanner[host].all_tcp_ports()]) This will create a CSV file called `scan_results.csv` that contains the following data: csv Host,State,Port 192.168.1.100,up,80 192.168.1.100,up,443 You can use the nmap module in Python to automate a wide variety of tasks. For example, you could use it to scan your network for open ports and services on a regular basis, or to create a vulnerability scanning script. *TCP, UDP, and Comprehensive scan with nmap using Python* Nmap can perform a variety of different scan types, including TCP scans, UDP scans, and comprehensive scans. * *TCP scans* are the most common type of scan, and they are used to identify open TCP ports and services on a network. * *UDP scans* are used to identify open UDP ports on a network. * *Comprehensive scans* combine TCP and UDP scans to provide the most complete picture of the open ports and services on a network. This video will show you how to use the nmap module in Python to perform TCP, UDP, and comprehensive scans. You will also learn how to parse the scan results and print them to the console or to a file. *Examples* The following Python script performs a TCP scan of the network for open ports on the specified IP address: import nmap # Create a new Nmap PortScanner object scanner = nmap.PortScanner() # Scan open TCP ports on specified IP address scanner.scan('192.168.1.100', arguments='-sS') # Print the scan results to the console for host in scanner.all_hosts(): print('Host : %s (%s)' % (host, scanner[host].hostname())) print('State : %s' % scanner[host].state()) for port in scanner[host].all_tcp_ports(): print('Port : %d (open)' % port) The following Python script performs a UDP scan of the network for open ports on the specified IP address: import nmap # Create a new Nmap PortScanner object scanner = nmap.PortScanner() # Scan the network for open UDP ports on the specified IP address scanner.scan('192.168.1.100', arguments='-sU') # Print the scan results to the console for host in scanner.all_hosts(): print('Host : %s (%s)' % (host, scanner[host].hostname())) print('State : %s' % scanner[host].state()) for port in scanner[host].all_udp_ports(): print('Port : %d (open)' % port) *Making a PortScanner Clone of NetDiscover Tools of Kali Using Python* NetDiscover is a popular network scanning tool that is included in Kali Linux. In this video, you will learn how to make a PortScanner clone of NetDiscover using Python. You will learn how to use the `nmap` module to scan a network for open ports and how to iterate over the scan results and print them to the console. *Chapters:* 00:00 Welcome to Cyber Secure Tec 00:10 Introduction to NMAP Scanner & nmap module 20:46 TCP, UDP and Comprehensive scan with nmap 30:20 Making PortScanner Clone of NetDiscover tools of Kali 43:08 Using Scapy Module to implement ARP protocols 54:46 Formatting Responses to get IP and MAC addresses of Clients I hope this video has been helpful. If you have any questions, please leave a comment below. #nmap #scapy #python #TCP #UDP #ARP

Download

1 formats

Video Formats

360pmp494.3 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Introduction to Nmap Scanner & Module with Python code | Complete Tutorial | NatokHD