How about asking interface from user as commandline argument(Use argparser or something ) and then work "base ip" from there. Much nicer than asking that base ip imo.
That's a great idea but I will be bound to unix. Well the reason why I created this was because I work for a company with very old network. All the sys admins who have more authority than me are all "windows experts". They also aren't familiar with tools like nmap lol. I created this to prove a point that they need to learn scripting to make their life easier since half the staff who knows what they are doing are gone
I am a trainee admin, but I doubt that they can show me anything useful ahahahah.
I can probably connect to google dns and retrieve the ip automatically tough to avoid picking up the lo. The downfall is that in the future if I need to ping all devices from a nic that doesn't connect to internet than I am kind of screw. I will figure a way out and update it later. Just picked up black hat python. Very very interesting book.
import subprocess
import threading
import time
import socket
def ping_it_boy(ip_addr):
p = subprocess.Popen(["ping","-n","1",ip_addr], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.read().split("\n"):
if line.strip().startswith("Reply from "):
l = line.strip().split()
m = line.replace(l[0]+" "+l[1]+" "+l[2], "")
if m.strip() != "Destination host unreachable.":
print(l[2][:-1] + " >>> " + m)
def get_ip_addr():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8",80))
ip = s.getsockname()[0]
base_ip = ip.split(".")[0] + "." + ip.split(".")[1] + "." + ip.split(".")[2] + "."
return base_ip
if __name__ == "__main__":
# ip = raw_input("Enter the base IP. Example: 192.168.1 \n>>> ")
# ip = ip.strip() + "."
ip = get_ip_addr()
print("Starting multiply threads for "+ ip + "0/24")
t_thread = []
t_sleep_on = 20
for i in range(1, 255):
t = threading.Thread(target=ping_it_boy, args=(ip + str(i),))
t_thread.append(t)
t.start()
if i == t_sleep_on:
# print("Threading sleeping: " + str(i))
for i in t_thread:
i.join()
t_thread.remove(i)
# print("Wakey Wakey")
t_sleep_on += 20