1
+ ##################################################################################
1
2
# Simple FritzCap python port
2
3
# Simplifies generation and examination of traces taken from AVM FritzBox and/or SpeedPort
3
4
# Traces can be examined using WireShark
4
5
# (c) neil.young 2010 (spongebob.squarepants in http://www.ip-phone-forum.de/)
5
- # based on the Windows GUI exe with same name
6
+ # based on the Windows GUI exe with same name#
7
+ ##################################################################################
6
8
7
9
import urllib , threading , sys
8
10
9
- # Configuration (just change here)
11
+ # Configuration (just change here) ###############################################
10
12
boxname = 'speedport.ip' # or ip (also fritz.box)
11
- password = 'yourpassword' # your password
13
+ password = 'yourpassword' # your password, adapt
12
14
protocol = 'https' # or http
13
15
capfile = 'test.cap' # name of capture file
14
-
15
- # URL templates
16
- url = protocol + '://' + boxname + '/cgi-bin'
16
+ login_required = 1 # set to 0 if no login is required
17
+ ##################################################################################
17
18
18
19
# Commands
19
20
login = 'getpage=../html/de/menus/menu2.html&errorpage=../html/index.html&var:lang=de&var:pagename=home&var:menu=home&=&login:command/password=%s'
20
- start = '/capture_notimeout?start=1&start1=Start'
21
- stop = '/capture_notimeout?stop=1&stop1=Stop'
22
-
23
-
24
- # Attempt to login
25
- command = urllib .urlopen (url + '/webcm' , login % password )
26
- response = command .read ()
27
- print 'Login' , response
21
+ start = '?start=1&start1=Start'
22
+ stop = '?stop=1&stop1=Stop'
28
23
24
+ # Tracer runs in a separate thread
29
25
class TraceGetter (threading .Thread ):
30
26
def __init__ (self , url , filename ):
31
27
self .url = url
@@ -34,6 +30,7 @@ def __init__(self, url, filename):
34
30
threading .Thread .__init__ (self )
35
31
36
32
def monitor (self , n1 , n2 , n3 ):
33
+ # n1: running number, n2: chunk size, n3: file size or -1 if unknown
37
34
print ["|" , "/" , "-" , "\\ " ][self .i ], "\r " ,
38
35
self .i += 1
39
36
self .i %= 4
@@ -45,11 +42,23 @@ def run(self):
45
42
except :
46
43
print "Could not open %s" % self .url
47
44
45
+ # Main
46
+ def main ():
47
+ # Attempt to login
48
+ if login_required :
49
+ command = urllib .urlopen (protocol + '://' + boxname + '/cgi-bin/webcm' , login % password )
50
+ response = command .read ()
51
+ print 'Login' , response
52
+
53
+ # Start tracer thread, wait for console input to stop
54
+ thread = TraceGetter (protocol + '://' + boxname + '/cgi-bin/capture_notimeout' + start , capfile )
55
+ thread .start ()
56
+ print "Trace started, stop with <ENTER>"
57
+ raw_input ()
58
+ # Clean stop
59
+ print "Stopping trace"
60
+ urllib .urlopen (protocol + '://' + boxname + '/cgi-bin/capture_notimeout' + stop )
61
+ print "Capture done"
48
62
49
- thread = TraceGetter (url + start , capfile )
50
- thread .start ()
51
- print "Trace started, stop with <ENTER>"
52
- raw_input ()
53
- print "Stopping trace"
54
- urllib .urlopen (url + stop )
55
- print "Capture done"
63
+ if __name__ == "__main__" :
64
+ main ()
0 commit comments