How to make random sampling from the Internet?

I’m trying to get a random selection of web pages, I don’t want to give up Google search results for various reasons. Here is how I tried it:

import socket
from random import randint

def doesitserveawebpage(ip):
    ip=str(ip)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((ip, 80))
        s.shutdown(2)
        return True
    except:
        return False

def givemerandomwebsite():
    adrformat = "%d.%d.%d.%d"
    while True:
        adr = adrformat % tuple(randint(0,255) for _ in range(4))
        try:
            print "Tring %s" % adr
            name = socket.gethostbyaddr(adr)
            if (doesitserveawebpage(adr)):
                return name
            else:
                continue
        except socket.herror:
            continue

Well, that doesn't work. Firstly, it is too slow. Secondly, it gives me addreses that do not serve web pages. Anyway, can I make this code better, or will you suggest another way to solve this problem?

+5
source share
2 answers

Assuming that most HTTP servers are running on a host with a domain name (for example, not just an IP address), you can additionally check your random IP addresses by doing a DNS lookup, for example. dig.

, IP-, IP.

+1

...

  • , , (a) (b) , .

  • , - : (a) 80 - - . , , 80 . () , . . URL- HTTP. (c) , .

1. . .

, 2. . , - .

.

, -, IPv6, , . , .

0

All Articles