2021-04-29 16:42:18 +00:00
|
|
|
import socket
|
|
|
|
|
|
|
|
|
|
targetHost = "127.0.0.1"
|
2021-05-17 10:58:35 -06:00
|
|
|
targetPort = 9999
|
2021-04-29 16:42:18 +00:00
|
|
|
print(targetHost)
|
|
|
|
|
|
|
|
|
|
#create a socket object
|
|
|
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
|
|
|
|
|
#connect the client
|
|
|
|
|
client.connect((targetHost, targetPort))
|
|
|
|
|
|
|
|
|
|
#send some data
|
|
|
|
|
message = "GET / HTTP/1.1\r\nHost: google.com\r\n\r\n"
|
|
|
|
|
#we have to encode our string using UTF-8
|
2021-05-17 10:58:35 -06:00
|
|
|
client.send(message.encode("utf-8"))
|
|
|
|
|
#client.send(b"GET / HTTP/1.1\r\nHost: google.com\r\n\r\n") ##THIS LINE ENCODE THE STRING AT UTF-8 using the 'b'
|
2021-04-29 16:42:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#receive some data
|
|
|
|
|
response = client.recv(4096) #This is the amount of bytes you want to read!!
|
|
|
|
|
|
2021-05-17 10:58:35 -06:00
|
|
|
client.close()
|
|
|
|
|
|
2021-04-29 16:42:18 +00:00
|
|
|
#print the response
|
|
|
|
|
print(response)
|