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

Port scanner with sockets

Sockets are the fundamental building block for network communications and in an easy way we can check whether a specific port is open, closed, or filtered by calling the connect_ex method.

For example, we could have a function that accepts by parameters an IP and a list of ports and return for each port whether it is open or closed.

In this example, we need to import the socket and sys modules. If we execute the function from our main program, we see how it checks each of the ports and returns whether it is open or closed for a specific IP address. The first parameter can be either an IP address or a domain name since the module is able to resolve a name from an IP and vice versa.

You can find the following code ...

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