What about an example of using the webbrowser as the frontend? I use some pen-testing suites that use html as the GUI.
Here is an example, kind of ugly since it is just to demonstrate what you can do.
Also, I am no web developer so the html was mostly pulled from w3schools.com.
Example:
import socket, webbrowser
#setup our socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#set socket to reuse address, if you don't you will eventually get
#socket errors with repetitive access
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
#bind socket to localhost and port 44444
s.bind(('',44444))
#I am not a web developer and most of this was from
#w3schools.com
page = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>GUI via web page</h1>
<p>Some examples of using html for a GUI</p>
<ol>
<li>Element 1</li>
<li>Element 2</li>
<li>So on..</li>
<li>And so on.</li>
</ol>
<form name="input" action="html_form_action.asp" method="get">
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" /><br />
Password: <input type="password" name="pwd" /><br />
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female<br />
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car<br />
Username: <input type="text" name="user" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>"""
car_page = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>
Car
</h1>
<p>
I have a car too, it is a Scion tC!
</p>
</body>
</html>
"""
bike_page = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>
Bike
</h1>
<p>
I don't have a bike....
</p>
</body>
</html>
"""
loggedin_page = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>
Logged in
</h1>
<p>
You are now logged in, welcome.
</p>
</body>
</html>
"""
started = 0
while 1:
#listen for connection
s.listen(1)
#check an see if this is the first time running
#if so, open the default browser to our server
#not needed, added for convince
if started == 0:
webbrowser.open_new("http://localhost:44444")
started = 1
else:
#accept connection and create objects to handle it
conn, addr = s.accept()
#get data from browser
data = conn.recv(10000)
print data
#check and see if the browser POSTed data to us
if "html_form_action.asp?" in data:
#look for stuff from forms and send appropreate page
if "Bike" in data:
conn.send(bike_page)
elif "Car" in data:
conn.send(car_page)
else:
conn.send(loggedin_page)
else:
conn.send(page)
#close connection so we can get more data if sent
conn.close() Tech B
Posting Whiz in Training
268 posts since May 2009
Reputation Points: 59
Solved Threads: 33
Skill Endorsements: 0