Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

Synchronous scanning

In this example, we implemented a class that allows us to scan an IP address and a list of ports that are passed to the script as a parameter.

In the main program, we add the necessary configuration for the treatment of the input parameters. We perform a loop that processes each port sent by parameter, and call the nmapScan (ip, port) method of the NmapScanner class.

You can find the following code in the filename: NmapScanner.py:

import optparse, nmapclass NmapScanner:    def __init__(self):        self.nmsc = nmap.PortScanner()    def nmapScan(self, host, port):        self.nmsc.scan(host, port)        self.state = self.nmsc[host]['tcp'][int(port)]['state']        print " [+] "+ host + " tcp/" + port + " " + self.statedef main(): parser = optparse.OptionParser("usage%prog ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content