بايثون

إنشاء برنامج مسح للشبكه بأستخدام بايثون

سنتحدث في هذا المنشور عن كيفية إنشاء سكريبت يقوم بمسح الشبكه من خلال بايثون والعثور على الاجهزة التي تعمل على الشبكه

هناك العديد من الطرق لانشاء هذا السكربت قمت بأختيار الكود التالي الذي اثبت فعاليته على معظم أنظمت التشغيل

لقد استخدمت بعض الموديولات في بايثون مثل

مقالات ذات صلة

threading

os

Platform

تحميل السكريبت

import platform
import os
from datetime import datetime
import threading
from queue import Queue

net = input("Enter the IP address: ")
st1 = int(input("Enter the Starting Number: "))
en1 = int(input("Enter the Last Number: "))

def Ip_Scanner(host_ip,host,ping1):
    print_lock = threading.Lock()
    try:
       addr = host_ip + str(host)
       comm = ping1 + addr
       response = os.popen(comm)
       for line in response.readlines():
          if (line.count("TTL")  or  line.count("ttl") ):
             print (addr, "--> Live")
    except:
        pass

def threader(net2,ping1):
    while True:
        worker = q.get()
        Ip_Scanner(net2,worker,ping1)
        q.task_done()


def main_Ip_Scanner(net,st1,en1):
    net1= net.split('.')
    a = '.'
    net2 = net1[0] + a + net1[1] + a + net1[2] + a
    en1 = en1 + 1
    oper = platform.system()
    if (oper == "Windows"):
       ping1 = "ping -n 1 "
    elif (oper == "Linux"):
       ping1 = "ping -c 1 "
    else :
       ping1 = "ping -c 1 "
    t1 = datetime.now()
    print ("\nScanning in Progress:\n")
    # how many threads are we going to allow for
    for x in range(100):
         t = threading.Thread(target=threader, args=(net2,ping1,))

         # classifying as a daemon, so they will die when the main dies
         t.daemon = True

         # begins, must come after daemon definition
         t.start()

    for worker in range(st1,en1):
        q.put(worker)

    # wait until the thread terminates.
    q.join()
    
    t2 = datetime.now()
    total = t2 - t1
    print ("Scanning completed in: ",total)

q = Queue()

main_Ip_Scanner(net,st1,en1)

Mustapha Haouili

مهندس تطوير برمجيات - مسؤول نظام تكنولوجيا المعلومات مع خبرة ناجحة من 14 عامًا. لغات البرمجة: Cobol - C # - Python - Shell Script. لا توجد مشكلة بدون حل

مقالات ذات صلة

اترك تعليقاً

زر الذهاب إلى الأعلى