python區域網alive ip偵聽

2021-09-07 12:13:04 字數 4295 閱讀 7430

python區域網alive ip偵聽

日期:夏季

注:寫著玩,歡迎copy

# -*- coding: cp936 -*-

# coding = utf-8

import os

import re

import thread

import time

import socket

import sys

def ping_ip(curr_ip):

global count_thread,lock,threadsnum

#print "*****************chile_thread-begin****************"+"\n"

ping_cmd = "ping" +" "+curr_ip

ping_answer = os.popen(ping_cmd).readlines()

patt = r'ttl=([0-9])'

ttl_str=re.findall(patt,ping_answer[2])

if len(ttl_str) == 0:

#print curr_ip+"is not alive"

pass

#print "*****************chile_thread-over****************"+"\n"

else:

hostinfo = socket.gethostbyaddr(curr_ip)

mac_address=get_mac_addr(curr_ip)

#print "mac_address"+mac_address

print "\n"+"alive host-----> "+"hostcomputername:"+hostinfo[0]+" mac_address:"+mac_address+"\t"+"ip:"+curr_ip

#print "*****************chile_thread-over****************"+"\n"

lock.acquire()

count_thread = count_thread+1

if count_thread ==threadsnum:

print "*****************network_end***************"

lock.release()

def get_mac_addr(curr_ip):

mac_cmd = "nbtstat -a "+curr_ip

mac_info = os.popen(mac_cmd).readlines()

mac_info_sum=""

for index in range(0,len(mac_info)):

mac_info_sum=mac_info_sum+mac_info[index]

patt_mac = r'= (.-.-.-.-.-.)'

mac_addr= re.findall(patt_mac,mac_info_sum)

return mac_addr[0]

def getaliveip(net_ip_init,ipbegin,ipend):

splitip = net_ip_init.split(".")

ip1=splitip[0]

ip2=splitip[1]

ip3=splitip[2]

prefix_ip = ip1+"."+ip2+"."+ip3+"."

for ip_last in range(ipbegin,ipend+1):

curr_ip=prefix_ip+str(ip_last)

thread.start_new_thread(ping_ip, (curr_ip,))

time.sleep(2)

def getnetgate():

netgate_cmd = "ipconfig /all"

netgate_info = os.popen(netgate_cmd).readlines()

netgate_info_str = ""

for index in range(0,len(netgate_info)):

netgate_info_str=netgate_info_str+netgate_info[index]

#print netgate_info_str

#print type(netgate_info_str)

patt_hn = r'主機名 . . . . . . . . . . . . . : (.+)'

host_name_local = re.findall(patt_hn,netgate_info_str)

rent_ip_begin=r'獲得租約的時間 . . . . . . . . . : (.+)'

rent_ip_begins=re.findall(rent_ip_begin,netgate_info_str)

rent_ip_end=r'租約過期的時間 . . . . . . . . . : (.+)'

rent_ip_ends=re.findall(rent_ip_end,netgate_info_str)

patt_ipv6 = r'本地鏈結 ipv6 位址. . . . . . . . : ([a-z0-9]::[a-z0-9]:[a-z0-9]:[a-z0-9]:[a-z0-9]%[0-9])'

ipv6 = re.findall(patt_ipv6,netgate_info_str)

patt_ipv4 = r'ipv4 位址 . . . . . . . . . . . . : ([0-9].[0-9].[0-9].[0-9])'

ipv4 = re.findall(patt_ipv4,netgate_info_str)

yanmas= r'子網掩碼 . . . . . . . . . . . . : ([0-9].[0-9].[0-9].[0-9])'

ym = re.findall(yanmas,netgate_info_str)

netgates = r'預設閘道器. . . . . . . . . . . . . : ([0-9].[0-9].[0-9].[0-9])'

ng = re.findall(netgates,netgate_info_str)

patt_dhcp = r'dhcp 已啟用 . . . . . . . . . . . : (.)'

dhcp_is=re.findall(patt_dhcp,netgate_info_str)

patt_dhcp_server = r'dhcp 伺服器 . . . . . . . . . . . : ([0-9].[0-9].[0-9].[0-9])'

dhcp_server = re.findall(patt_dhcp_server,netgate_info_str)

print "本地主機名: "+host_name_local[0]

print "子網掩碼: "+ym[0]

print "預設閘道器: "+ng[0]

print "是否啟用dhcp: "+dhcp_is[0]

print "dhcp伺服器ip: "+dhcp_server[0]

return ng[0]

if __name__ == "__main__":

count_thread = 0

lock = thread.allocate_lock()

print "*****************network_begin**************"

net_ip_init=getnetgate()

ipbegin = raw_input("請輸入偵聽起始ip:")

ipend = raw_input("請輸入偵聽結束ip:")

intipbegin = int(ipbegin)

intipend = int(ipend)

threadsnum = intipend+1-intipbegin

getaliveip(net_ip_init,intipbegin,intipend)

執行截圖:

python攻擊區域網電腦 區域網攻擊

目錄 區域網內的欺騙攻擊主要有以下幾種 arp欺騙 dns欺騙 netbios名稱欺騙和llmnr欺騙 進行內網攻擊的第一步是先檢視我們自己網絡卡的配置資訊,從而得知內網網段的資訊。探測內網資訊 檢視自己網絡卡配置資訊有好多命令,常用的有下面幾個,我們主要是檢視ip 子網掩碼和閘道器資訊 nmcli...

Python獲取區域網IP(ping)

coding utf 8 author 田園小菜籽 date 2018 12 11 python3.x ip scaner.py 使用方法樣例 python ip scaner.py 192.168.1.1 會掃瞄192.168.1.1 255的ip 多執行緒加速後大概十幾秒 import plat...

區域網是什麼 區域網的介紹

區域網 local area network,l是指在某一區域內由多台計算機互聯程式設計客棧成的計算機組。一般是方圓幾千公尺以內。區域網可以實現檔案管理 應用軟體共享 印表機共享 工作組內的日程安排 電子郵件和傳真通訊服務等功能。區域網是封閉型的,可以由辦公室www.cppcns.com內的兩台計算...