-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLanscanner.py
31 lines (27 loc) · 1005 Bytes
/
Lanscanner.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
import socket
class LanScanner():
def __init__(self):
self.hostname = socket.gethostname()
self.networkIP = socket.gethostbyname(self.hostname)
self.networkPrefix = self .networkIP.split(".")
del(self.networkPrefix[-1])
self.networkPrefix = ".".join(self.networkPrefix)
def checkIp(self, currentIP):
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.settimeout(0.01)
if not s.connect_ex((currentIP,135)):
s.close()
return 1
else:
s.close()
def startScan(self):
print('Your IP is : %s' % (self.networkIP))
print('scanning Lan network')
for ip in range(1,255):
currentIP = self.networkPrefix + '.'+str(ip)
if self.checkIp(currentIP):
print('%s \t- %s' % (currentIP , socket.getfqdn(currentIP)))
print("Scanning completed")
if __name__ == '__main__':
sLan = LanScanner()
sLan.startScan()