G
G
GilbertAmethyst2018-07-15 17:51:47
Python
GilbertAmethyst, 2018-07-15 17:51:47

How to scan a local network?

Hello.
There is a program:
Advanced ip scanner
Task:
Similar to this program, scan the local network and get devices connected to it using Python. All the solutions that I found, for some reason, do not find the devices that this program finds. The local network is organized using a router.
Current copy-paste code (python3):

Delicious copy-paste
import os
import time
from subprocess import Popen
import sys

devnull = open(os.devnull, 'wb')

p = []
active = 0
unknown = 0
passive = 0


for f_part in range(0,2):
    for s_part in range(0,256):
        ip = "192.168." + str(f_part) + "." + str(s_part)
        if os.name == 'nt':
            CREATE_NO_WINDOW = 0x08000000
            p.append((ip, Popen(['ping', '-c', '3', ip], stdout=devnull, creationflags=CREATE_NO_WINDOW)))
        else:
            p.append((ip, Popen(['ping', '-c', '3', ip], stdout=devnull)))
while p:
    for i, (ip, proc) in enumerate(p[:]):
        if proc.poll() is not None:
            p.remove((ip, proc))
            if proc.returncode == 0:
                print('%s Active' % ip)
                active = active + 1
            elif proc.returncode == 2:
                print('%s Unknown' % ip)
                active = unknown + 1
            else:
                print('%s Passive' % ip)
                passive = passive + 1
    time.sleep(.04)
devnull.close()


print("Your system: ",os.name)
print("Active  [ ",active," ]")
print("Passive [ ",passive," ]")
print("Unknown  [ ",unknown," ]")
input("")
My code says that there are no active addresses in the local network:
5b4b5f7a84211332682233.jpegAnd here is the result from the program:
5b4b5f728d257586928924.jpegTell me how to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
be52, 2018-07-15
@be52

https://xael.org/norman/python/python-nmap/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question