-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPScanner.py
More file actions
68 lines (58 loc) · 3.12 KB
/
IPScanner.py
File metadata and controls
68 lines (58 loc) · 3.12 KB
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
###################################################
###################################################
###### ######
###### IP Scanner ######
###### Author: Daniel Americo ######
###### Development Date: 28/09/2022 ######
###### Final Version Number: 1.0 ######
###### ######
###### This program is used to scan ######
###### a network and get a list ######
###### of all active IPs. ######
###### ######
###################################################
###################################################
import subprocess, time, os
def cls(): # Helper function to clear the console
os.system('cls' if os.name=='nt' else 'clear')
def logo():
print(" _____ _____ _____ ")
print("|_ _| __ \ / ____| ")
print(" | | | |__) | | (___ ___ __ _ _ __ _ __ ___ _ __ ")
print(" | | | ___/ \___ \ / __/ _` | '_ \| '_ \ / _ \ '__| ")
print(" _| |_| | ____) | (_| (_| | | | | | | | __/ | ")
print("|_____|_| |_____/ \___\__,_|_| |_|_| |_|\___|_| \n")
def ping(host):
command = ['ping', '-n', '1', host] # Creates a string with the given arguments to look like ("ping -n 1 host")
return subprocess.call(command) == 0 # returns true if the ping is successful
def main():
cls()
logo()
print("Format IP: XXX.XXX.XXX.0")
host = input("[*] Input local network IP: ")
#host = "140.159.251.0" VU IP to test on, 192.168.56.0 does not work.
try:
startHost = int(input("[*] Input start host number: "))
except ValueError: # Handles error if the user does not input a number
main()
try:
endHost = int(input("[*] Input end host number: "))
except ValueError: # Handles error if the user does not input a number
main()
print("\nScan started\n")
octets = host.split('.') # Splits host IP into 4 octets to use later
IP = octets[0] + "." + octets[1] + "." + octets[2] + "." # Add first 3 octets together to form almost complete IP
timer = time.perf_counter() # Creates a timer
for i in range(startHost, endHost + 1):
res = ping(IP+str(i)) # Adds the last octet (i) to the IP, completing it and then calling connect with the specified port (80)
if res: # If we receive back True
print(">>> Active device found at: " + IP+str(i) + f" [{time.perf_counter() - timer:.5f}]") # Shows what address we were successful in finding
print(f"[{time.perf_counter() - timer:.5f}] Done Scanning") # Prints total time, rounded to 5 decimal places (.5f)
while True: # Allows the user to either do another scan or quit the program
checkControl = input("[S]can again | [Q]uit\n[*] Action: ")
if checkControl == 's':
main() # Calls the main function
elif checkControl == 'q':
quit() # Quits the program
if __name__ == "__main__":
main()