Created
October 24, 2022 08:57
-
-
Save momenbasel/bc5736f72a7c97b3ad4d1087f9f99828 to your computer and use it in GitHub Desktop.
get ips from cidr file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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