Created
August 18, 2013 15:53
-
-
Save ygabo/6262341 to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/8196886/how-to-generate-tcp-ip-and-udp-packets-in-python if you you want to send/receive usual packets then you should use socket or socketserver http://docs.python.org/library/socket.html#module-socket
http://docs.python.org/library/socketserver.html#module-SocketServer
to send TCP to google's port 80 use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = 'google.com' # The remote host | |
PORT = 80 # The same port as used by the server | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((HOST, PORT)) | |
s.send('GET / HTTP/1.1\r\nHost: google.com\r\n\r\n') | |
data = s.recv(1024) | |
s.close() | |
print 'Received', repr(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment