As stated in my last post, lab 4 simulates computer censorship by filtering certain strings from client requests, sending reset commands to both the client and the server being requested.
After Jong’s lecture, I downloaded the lab4files.tar.gz and extracted the file to access the serverv3.c code. I put the .c file on ‘Ba’ so I could test whether my python code would work before I tried it against ‘Ta’. I compiled and ran the server code with the ‘&’ switch in order to make the server run in the background so I could test my lab4.py code:
./a.out 9082 &
The ‘9082’string is the port the server will be listening on.
The code I wrote was basically the same code Jong gave us in lecture, but I broke the strings up with the ‘.replace()’ function in python:
**********************************
for l in lines:
l = l.replace("antithesis", "anti\nthesis")
l = l.replace("fundamentally", "funda\nmentally")
l = l.replace("consequence", "conse\nquence")
l = l.replace("illuminated", "illu\nminated")
l = l.replace("viewpoint", "view\npoint")
**********************************
I would search for a keyword in the string, and then replace it with a newline character in the middle of the word: “anti\nthesis” would become:
‘Anti’
‘Thesis’
Once the keyword was broken-up, I would use the ‘split()’ function and send the current string, up until the split, to the server:
L2 = l.split(‘n’)
For x in l2:
s.send(x.strip())
time.sleep(1)
This was allowing the keyword to pass to the server, and the string was re-configured on the server side in its entirety.
I ran this code on Ba, configuring my lab4.py code to connect via the local host:
s.connect(("127.0.0.1", 9082))
After running my lab4.py code I received a ‘success’ response from the server; this tells me the strings are being broken-up and re-configured correctly...but would it work on ‘Ta’ ???
I ran my code from Alef to the server running the simulated censorship and received another ‘success’ response from the server:
[tjcdeba@Alef ~]$ python lab4_code.py
"What is Prof. Crandall (a.k.a. Jed, a.k.a. J-Dub, whatever you prefer)'s favorite Von Clausewitz quote?\nSuccess!\n"
Looks like lab 4 is done…on to lab 4.5!
Wednesday, April 22, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment