-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathwifinder.py
105 lines (79 loc) · 3 KB
/
wifinder.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
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
"""
Author : [email protected]
Licence : GPL v3 or any later version
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import nmap # import nmap.py
import time
import re
try:
nm = nmap.PortScanner() # instance of nmap.PortScanner
except nmap.PortScannerError:
print('Nmap not found', sys.exc_info()[0])
sys.exit(0)
except:
print("Unexpected error:", sys.exc_info()[0])
sys.exit(0)
hostList = []
gracePeriod = 7
def seek(): # function to scan the network
curHosts = []
nm.scan(hosts = '192.168.1.0/24', arguments = '-n -sP -PE -T5')
# executes a ping scan
localtime = time.asctime(time.localtime(time.time()))
print('============ {0} ============'.format(localtime))
# system time
for host in nm.all_hosts():
try:
mac = nm[host]['addresses']['mac']
vendor = nm[host]['vendor'][mac]
except:
vendor = mac = 'unknown'
curHosts.append((host,mac,vendor,gracePeriod))
updateHostList(curHosts)
for host in hostList:
print('Scan report for %s\nMAC Address: %s (%s)' % (host[0], host[1], host[2]))
print('Number of hosts: ' + str(len(hostList)))
return len(hostList) # returns count
def updateHostList(curHosts):
global hostList
if hostList == []:
hostList = curHosts
else:
hostList = [(x[0],x[1],x[2],x[3]-1) for x in hostList]
# only the hosts that were new in this iteration
newList = [(x[0],x[1],x[2],x[3]) for x in curHosts if not (any(x[0]==y[0] for y in hostList))]
for host in newList:
hostList.append(host)
for host in hostList:
if any(host[0] == y[0] for y in curHosts):
hostList[hostList.index(host)] = (host[0],host[1],host[2],gracePeriod)
for host in hostList:
if host[3] <= 0:
hostList.remove(host)
def beep(): # no sound dependency
print('\a')
if __name__ == '__main__':
old_count = new_count = seek()
startCounter = gracePeriod
# are there any new hosts?
while (new_count <= old_count) or startCounter >= 0:
startCounter -= 1
time.sleep(1) # increase to slow down the speed
old_count = new_count
new_count = seek()
# DANGER!!!
print('OHSHITOHSHITOHSHITOHSHITOHSHIT!')
beep()