Skip to content

Instantly share code, notes, and snippets.

@momenbasel
Created October 24, 2022 08:57
Show Gist options
  • Save momenbasel/bc5736f72a7c97b3ad4d1087f9f99828 to your computer and use it in GitHub Desktop.
Save momenbasel/bc5736f72a7c97b3ad4d1087f9f99828 to your computer and use it in GitHub Desktop.
get ips from cidr file
from netaddr import IPNetwork
import socket
from contextlib import closing
ips = open("ips.txt", "r") #insert here IP file here
ip_arr= (ips.read().strip()).split('\n')
def check_socket(host, port):
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
if sock.connect_ex((host, port)) == 0:
msg= "\t"+host+"\t has port "+ port+ " open!"
print(msg)
for ip_str in ip_arr:
msg="going through ip:\t"+ ip_str
print(msg)
for ip in IPNetwork(ip_str):
print(ip)
check_socket(str(ip),80)
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment