-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathfind.webservers.py
More file actions
75 lines (54 loc) · 1.79 KB
/
find.webservers.py
File metadata and controls
75 lines (54 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
"""
Find Open Webservers
You need a list of subnets to scan
For example, all possible syrian networks:
https://ghostbin.com/paste/meuxy
Save it as 'ips.txt' in the same directory as this script
"""
import socket
import subprocess
import sys
from datetime import datetime
import re
from ipaddress import *
# Clear the screen
subprocess.call('clear', shell=True)
# Get list of syrian IPS:
# open the list of ips
f=open('ips.txt')
lines=f.readlines()
#iterate over them
for line in lines:
#remoteServerIP = socket.gethostbyname(line)
line = line.strip('\n')
for addr in IPv4Network(line):
addr = str(addr)
# Print a nice banner with information on which host we are about to scan
print ("-" * 60)
print ("Please wait, scanning remote host %s" % addr)
print ("-" * 60)
# Check what time the scan started
t1 = datetime.now()
try:
for port in (80,443):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((addr,port))
if result == 0:
print ("Port {}: \t Open".format(port))
sock.close()
except KeyboardInterrupt:
print ("You pressed Ctrl+C")
sys.exit()
except socket.gaierror:
print ('Hostname could not be resolved. Exiting')
sys.exit()
except socket.error:
print ("Couldn't connect to server")
sys.exit()
# Checking the time again
t2 = datetime.now()
# Calculates the difference of time, to see how long it took to run the script
total = t2 - t1
# Printing the information to screen
print ('Scanning Completed in: %s ' % total)