Created
November 28, 2017 09:03
-
-
Save KurzGedanke/2cbf215d13d823af689b34aa47af1b99 to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
A script which scans _all_ ipv4 address for server which have | |
Index of / landing page. | |
Your ISP will probably not only hate you for this, it will kill your conection. | |
You will send (4.294.967.296 - the reversed addresses) requests in a very | |
'short' amount of time. | |
""" | |
import re | |
import requests | |
def count_ip(): | |
''' | |
A generator who counts from ip 0.0.0.0 to 255.255.255.255 and yield | |
every ip as a string back. | |
''' | |
ipAddress = [000, 000, 000, 000] | |
# Need to find a nicer way for this, but hey, it works. | |
for x in range(0, 256): | |
ipAddress[0] = x | |
for y in range(0, 256): | |
ipAddress[1] = y | |
yield f'{ipAddress[0]}.{ipAddress[1]}.{ipAddress[2]}.{ipAddress[3]}' | |
for i in range(0, 256): | |
ipAddress[2] = i | |
yield f'{ipAddress[0]}.{ipAddress[1]}.{ipAddress[2]}.{ipAddress[3]}' | |
for j in range(0, 256): | |
ipAddress[3] = j | |
yield f'{ipAddress[0]}.{ipAddress[1]}.{ipAddress[2]}.{ipAddress[3]}' | |
yield f'{ipAddress[0]}.{ipAddress[1]}.{ipAddress[2]}.{ipAddress[3]}' | |
def check_if_index_of(ip): | |
''' | |
Makes an http requests to the desired address and return the ip if it has | |
a "Index of" header. | |
''' | |
regex = r"<h1>Index of .*<\/h1>" | |
try: | |
r = requests.get(f'http://{ip}', timeout=1) | |
founds = re.findall(regex, r.text) | |
if founds and founds is not 'none': | |
return ip + '\n' | |
else: | |
return '' | |
# print('Found nothing...') | |
except: | |
# print('Something went wrong. :(') | |
return '' | |
def main(): | |
ips = count_ip() | |
with open('notes.txt', 'a') as hostFile: | |
for ip in ips: | |
print(str(check_if_index_of(ip)) + '\n') | |
hostFile.write(str(check_if_index_of(ip))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment