Created
March 29, 2012 20:28
-
-
Save erikkaplun/2243405 to your computer and use it in GitHub Desktop.
proxy
This file contains hidden or 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
#!/usr/bin/python | |
# coding: utf-8 | |
import socket | |
import time | |
s = socket.socket() | |
#host = '195.50.209.244' | |
host = '127.0.0.1' | |
#port = 80 | |
port = 8000 | |
msg = "GET /;stream.mp3 HTTP/1.1\r\n" | |
msg += "Host: 127.0.0.1:8005\r\n" | |
msg += "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0\r\n" | |
msg += "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" | |
msg += "Accept-Language: en-us,en;q=0.5\r\n" | |
msg += "Accept-Encoding: gzip, deflate\r\n" | |
msg += "Connection: keep-alive\r\n\r\n" | |
#print(msg) | |
print "Connecting..." | |
s.connect((host, port)) | |
print "Sending..." | |
s.send(msg) | |
print "Sleeping..." | |
time.sleep(1) | |
#print s.recv(1024) | |
print "Closing connection..." | |
s.close() | |
print "Done." |
This file contains hidden or 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
#!/usr/bin/python | |
# coding: utf-8 | |
import socket | |
import select | |
import sys | |
REMOTE_ADDR = ('195.50.209.244', 80) | |
LOCAL_ADDR = ('127.0.0.1', 8000) | |
CONNECTIONS = [] | |
def main(): | |
listener = socket.socket() | |
listener.setblocking(0) | |
listener.bind(LOCAL_ADDR) | |
listener.listen(5) | |
size = 1024 | |
input = [listener, sys.stdin] | |
running = True | |
while running: | |
print "Waiting..." | |
ready_to_read, ready_to_write, in_error = select.select(input, [], [], 1) | |
for connection in ready_to_read: | |
if connection == listener: | |
print "Something trying to connect..." | |
# handle the server socket | |
client, address = listener.accept() | |
print "Client accepted." | |
input.append(client) | |
elif connection == sys.stdin: | |
print "Exiting..." | |
sys.stdin.readline() | |
running = 0 | |
else: | |
print "Client sending data..." | |
data = connection.recv(size) | |
if data: | |
print "Client sent data; echoing..." | |
connection.send(data) | |
else: | |
print "Client disconnected." | |
connection.close() | |
input.remove(connection) | |
print "Done." | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment