FinlayDaG33k
Posts: 14
Joined: Mon Feb 22, 2016 5:56 pm

Python Script not working

Wed Feb 24, 2016 4:01 pm

hii there guys,

I build this python script, but it is not working properly.
http://pastebin.com/SzrKHUen
it says that google.com on port 80 is down, whilist ofcourse, it isn't.
I know it should be a bug somewhere in the code, but I can't find it as I started python like half an hour ago.

can someone tell me what's wrong?

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Python Script not working

Wed Feb 24, 2016 4:16 pm

The value for port in s.connect() needs to be an integer value (80), but you are giving it a string ("80"). Convert it to an integer and you should be OK.

Debugging hint: Put some extra print statements inside the try/except block to see which line it was failing at.

Code: Select all

def check_ping(host,port):
    captive_dns_addr = ""
    host_addr = ""
    try:
        host_addr = socket.gethostbyname(host)
 
        if (captive_dns_addr == host_addr):
            return False
 
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print "Created socket"
        s.settimeout(1)
        print "Timeout set"
        s.connect((host,port))
        print "Connection opened"
        s.close()
    except:
        return False
 
    return True

FinlayDaG33k
Posts: 14
Joined: Mon Feb 22, 2016 5:56 pm

Re: Python Script not working

Wed Feb 24, 2016 4:48 pm

Thanks, I managed to solve it :D

Return to “Python”