5 Python Libraries for Cyber Security

Chris Doucette
3 min readDec 10, 2018
Photo by Marius Masalar on Unsplash

Introduction

Python is currently one of the fastest growing and most in demand languages. It’s usefulness has been proven in software engineering and data science. Another useful application of the language is for building cyber security tools. In this article, I would like to share with you some of my favorite libraries for building cyber security tools.

Requests

Requests is one of my most used libraries by far and it is for many others as it is one of the most downloaded Python libraries at 400,000 downloads each day. Requests is used for crafting HTTP requests within your Python scripts. This is useful for calling public APIs and grabbing HTML pages.

Installation:

$ pip install requests

Example:

import requestsurl = 'https://haveibeenpwned.com/api/v2/breachedaccount/test@example.com'result = requests.get(url)print(result.text)# [{"Name":"000webhost","Title":"000webhost"...}]

Scapy

Scapy is a useful libary for interacting with packets. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, store or read them using pcap files, match requests and replies, and much more. It is very useful for creating a network scanner to a packet sniffer

Installation:

$ pip install scapy

Example:

from scapy.all import sr1,IP,ICMP

p=sr1(IP(dst='8.8.8.8')/ICMP())
if p:
p.show()

Nmap

Nmap is a well-known open source network scanner. This library allows you to integrate nmap with your Python scripts so you are able to use the power of nmap to scan hosts and then interact with the data within your Python script.

Installation:

$ pip install python-nmap

Example:

import nmapnm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')

for host in nm.all_hosts()…

--

--