I want to know the active IPs on my network and to do this I'm pinging a range of addresses, but it won't let me. It says that it requires administrative privileges. Does anyone know? Does anyone know how to fix it?
Here's the code in case it's useful:
import subprocess
import os
for ip in range(255):
ipAddres='192.168.1.'+str(ip)
respuesta=os.system("ping -c 1 "+ipAddres)
if respuesta:
print(ipAddres)
Operating system: Windows 10.
First, when you ping any host that is not active, it will return that a host is inaccessible, but if the host responds, it can return "bytes" then our script will start from there
This is the code, now I will explain each part how it works.
Here the subprocess module will be imported that will allow you to interact with the processes of the operating system and PIPE allows you to capture the output flow and if our process does not send any error
from subprocess import PIPE, Popen
Later, a function called ipRed will be created.
Now; A cycle will be created. A variable is created where the ip will be stored and the integer number will be formatted to string
A variable is created with the Popen method that this method will allow us to open a process, the command is passed as arguments, but if the command needs arguments a list is created, the variables are added and PIPE is assigned to it, it will allow the flow control of process.
A response variable is created that is the one that contains the response of our process.
As I had commented before, when performing a ping, if the destination host responds, it will send "bytes" then, with the responses we make a conditional that if in any of the outputs it returns "bytes=32" then the host is active.
This function is part of a script that I made in my company to verify some values of some stations that should have been turned on and it continues to work to this day. Returns "True" if the station pings, and "False" otherwise. I hope it helps you.