|
2 | 2 | from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
|
3 | 3 | from SocketServer import ThreadingMixIn
|
4 | 4 | import threading
|
5 |
| -import sys |
6 | 5 | import subprocess
|
7 |
| -from urlparse import parse_qs, urlparse |
8 |
| -import logging |
9 |
| -import os |
10 |
| - |
11 |
| - |
12 |
| -def locate(file): |
13 |
| - # Find the path for fping |
14 |
| - for path in os.environ["PATH"].split(os.pathsep): |
15 |
| - if os.path.exists(os.path.join(path, file)): |
16 |
| - return os.path.join(path, file) |
17 |
| - return "{}".format(file) |
18 | 6 |
|
19 | 7 |
|
20 | 8 | def doScan(ip):
|
21 |
| - # nmap -sP --host-timeout 1000 --max-retries 100 --dns-servers 192.168.2.3 192.168.2.* -oG n.tmp |
22 |
| - logger.info("START") |
23 | 9 | output = []
|
24 |
| - #ping_command = '{} -sP --host-timeout 1000 --max-retries 100 --dns-servers 192.168.2.3 {} -oG n.tmp'.format(filepath, ip) |
25 |
| - ping_command = '{} -sP --host-timeout 1 --max-retries 1 --dns-servers 192.168.2.3 {} -oG n.tmp'.format( |
| 10 | + ping_command = '{} -sP --host-timeout 10 --max-retries 5 --dns-servers 192.168.2.3 {} -oG n.tmp'.format( |
26 | 11 | "nmap", ip)
|
27 | 12 |
|
28 | 13 | # Execute and write output to file
|
29 | 14 | subprocess.Popen(ping_command, stdout=subprocess.PIPE,
|
30 | 15 | shell=True).communicate()
|
| 16 | + |
31 | 17 | # read file
|
32 | 18 | cmd_output = str(subprocess.Popen(
|
33 | 19 | "cat n.tmp", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()[0])
|
@@ -61,18 +47,7 @@ def do_GET(self):
|
61 | 47 |
|
62 | 48 |
|
63 | 49 | if __name__ == '__main__':
|
64 |
| - # Locate the path of fping |
65 |
| - global filepath |
66 |
| - filepath = locate("nmap") |
67 |
| - logger = logging.getLogger() |
68 |
| - handler = logging.StreamHandler() |
69 |
| - formatter = logging.Formatter( |
70 |
| - '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') |
71 |
| - handler.setFormatter(formatter) |
72 |
| - logger.addHandler(handler) |
73 |
| - logger.setLevel(logging.DEBUG) |
74 |
| - |
75 |
| - port = 9042 |
76 |
| - logger.info('Starting server port {}, use <Ctrl-C> to stop'.format(port)) |
| 50 | + port = 80 |
| 51 | + print('Starting toWipf device scanner Version 0.1 on port {}'.format(port)) |
77 | 52 | server = ThreadedHTTPServer(('0.0.0.0', port), StartScan)
|
78 | 53 | server.serve_forever()
|
0 commit comments