0

Hello I'm trying to call a specific object from the socket library, more specifically socket.send and socket.recv. The IDE i'm using is pycharm and its telling me that it cannot find the the reference in the socket library. Here is a snippet of my code:

def http(ip,port): 
    try:
        socket.setdefaulttimeout(2)
        a = socket.socket()
        a.connect((ip,port))
        socket.send("GET HTTP/1.1 \r\n")
        giveMeUrInfoz = socket.recv(1024)
        print "[+]" + "Huzzah! " + str(giveMeUrInfoz)
        print "**********************************************************"
        return giveMeUrInfoz
    except Exception, e:
        print "[-] Unable to grab info" + str(e)
        print "**********************************************************"
        return str(e)

The pycharm IDE is telling me that it does not recognize the send and recv objects. I know for a fact that the socket.send and socket.recv are valid objects part of the socket library per the following link to python docs :https://docs.python.org/2/library/socket.html.

My question is, why is this not working? I should also mention the purpose of this function in my script is to obtain the web server banner information via get request. I am passing port 80 into the function as well as a valid IP address.

0xa13x
  • 5
  • 3

1 Answers1

1

Instead of socket.send("GET HTTP/1.1 \r\n") and socket.recv(1024) you will want to use the send and recv command for an instantiated Socket Object.

So in your case it would be a.send("GET HTTP/1.1 \r\n") or a.recv(1024).

Cory Shay
  • 1,204
  • 8
  • 12