-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
executable file
·94 lines (71 loc) · 2.77 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# server
#
# Copyright 2013 Konrad Markus
#
# Author: Konrad Markus <[email protected]>
#
import sys
if sys.version < '2.7':
sys.exit('Python 2.7 is required.')
#import pathhack
import logging
from optparse import OptionParser
import daemon
# NOTE: edit config.rb as appropriate
from config.config import config
from fakeap.fakeap import FakeAP
from util.pidfile import PidFile
def main():
parser = OptionParser()
parser.add_option('--debug', '-d', action='store_true', default=False,
help='log debugging messages too')
parser.add_option('--log-stderr', '-l', dest='log_stderr',
action='store_true', default=False,
help='force log messages to stderr')
parser.add_option('--foreground', '-f', dest='foreground',
action='store_true', default=False,
help='do not run as daemon')
options, args = parser.parse_args()
if args:
parser.error('incorrect number of arguments')
if options.foreground:
server(options)
else:
# NOTE: the pidfile path must be the same as $PIDFILE in the init.d script
with daemon.DaemonContext(pidfile=PidFile('/var/run/fakeapd.pid')):
server(options)
def packet_callback(p):
print p.summary()
def server(options):
# configure logging
if options.debug or config.get('debug', False):
if options.log_stderr:
logging.basicConfig(level=logging.DEBUG,
stream=sys.stderr,
format='%(asctime)s [%(threadName)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
else:
logging.basicConfig(level=logging.DEBUG,
filename=config['logfile'],
format='%(asctime)s [%(threadName)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
else:
if options.log_stderr:
logging.basicConfig(level=logging.INFO,
stream=sys.stderr,
format='%(asctime)s [%(threadName)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
else:
logging.basicConfig(level=logging.INFO,
filename=config['logfile'],
format='%(asctime)s [%(threadName)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
# initialize the FakeAP
fakeAP = FakeAP(config['interface'], config['ESSID'], config['BSSID'], config['channel'], config['beacon_interval_sec'], packet_callback)
# start the FakeAP
fakeAP.start()
if __name__ == '__main__':
main()