Generate real random urls in python
This will create a random ip address using random.randint(0, 255) like this:
It will then try to get the hosts address by using socket.gethostbyaddr(url) and if it's good/real it will print the address and write it to the file links.txtip0 = str(random.randint(0, 255))
ip1 = str(random.randint(0, 255))
ip2 = str(random.randint(0, 255))
ip3 = str(random.randint(0, 255))
url = ip0 + '.' + ip1 + '.'+ ip2 + '.'+ ip3
import random, urllib2, os, socket, time
from threading import Thread, active_count
f=open("links.txt", 'w')
global p
global done
global alinks
alinks = []
maxurls = 100
p=0
def main():
global alinks
global done
global p
while p != maxurls:
ip0 = str(random.randint(0, 255))
ip1 = str(random.randint(0, 255))
ip2 = str(random.randint(0, 255))
ip3 = str(random.randint(0, 255))
url = ip0 + '.' + ip1 + '.'+ ip2 + '.'+ ip3
try:
link = socket.gethostbyaddr(url)
print link[0]
f.write(link[0])
f.write("\n")
p=p+1
try:
urlContent = urllib2.urlopen(url).read()
if urlContent.find('<html') > -1 or urlContent.find('<HTML') > -1:
break
except:
pass
except:
pass
done = done - 1
maxi = 55
done = maxi
hhh = 0
while hhh != maxi:
hhh=hhh+1
Thread(target=main, args=()).start()
while done != 0 or done > 0:
time.sleep(1.2)
print "Writing to File"
alinks.tofile(f)
print "Done exiting"
Download - mediafire.com
Download - codepanel.net
No comments:
Post a Comment