Advertisement
franji

Untitled

Jan 24th, 2018
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import socket
  2. import sys
  3.  
  4.  
  5. def WGet(hostname, port, urlpath):
  6.     ip = socket.gethostbyname(hostname)
  7.     print "Connecting to address: ", ip
  8.     soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9.     soc.connect((ip, port))
  10.     request = """GET {} HTTP/1.0
  11. Host:{}
  12.  
  13. """.format(urlpath, hostname)
  14.     soc.send(request.replace("\n", "\r\n"))
  15.     data = soc.recv(4096)
  16.     while data:
  17.         print data
  18.         data = soc.recv(4096)
  19.  
  20.  
  21.  
  22. def main(argv):
  23.     #WGet("bootstrap.pypa.io", 80, "/get-pip.py")
  24.     WGet("127.0.0.1", 8081, "/")
  25.  
  26. if __name__ == '__main__':
  27.     sys.exit(main(sys.argv))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement