python局域网alive ip侦听


作者:vpoet

mails:vpoet_sir@163.com

注:写着玩,欢迎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]{2})'
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'= (.{2}-.{2}-.{2}-.{2}-.{2}-.{2})'
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]{3,4}::[a-z0-9]{3,4}:[a-z0-9]{3,4}:[a-z0-9]{3,4}:[a-z0-9]{3,4}%[0-9]{2})'
ipv6 = re.findall(patt_ipv6,Netgate_info_Str) patt_ipv4 = r'IPv4 地址 . . . . . . . . . . . . : ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'
ipv4 = re.findall(patt_ipv4,Netgate_info_Str) YanMas= r'子网掩码 . . . . . . . . . . . . : ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'
YM = re.findall(YanMas,Netgate_info_Str) Netgates = r'默认网关. . . . . . . . . . . . . : ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'
Ng = re.findall(Netgates,Netgate_info_Str) Patt_dhcp = r'DHCP 已启用 . . . . . . . . . . . : (.{1,2})'
dhcp_Is=re.findall(Patt_dhcp,Netgate_info_Str) Patt_dhcp_server = r'DHCP 服务器 . . . . . . . . . . . : ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'
dhcp_server = re.findall(Patt_dhcp_server,Netgate_info_Str) print "本地主机名: "+Host_Name_Local[0]
print "本机IPv6地址: "+ipv6[0]
print "本机IPv4地址: "+ipv4[0]
print "子网掩码: "+YM[0]
print "默认网关: "+Ng[0]
print "是否启用DHCP: "+dhcp_Is[0]
print "DHCP服务器IP: "+dhcp_server[0]
print "动态租约起始时间: "+Rent_Ip_Begins[0]
print "动态租约过期时间: "+Rent_Ip_Ends[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局域网alive ip侦听的更多相关文章

  1. SQL Server使用侦听器IP访问时遇到"The target principal name is incorrect. Cannot generate SSPI context"

    在测试SQL Server 2016 Always On时,在创建侦听器后,在客户端使用SSMS, 可以用侦听器名称访问Always On集群,但是使用侦听器IP访问时遇到"The targ ...

  2. WCF:没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的。

    没有终结点在侦听可以接受消息的 http://xx.com/WebService.svc. 这通常是由于不正确的地址或者 SOAP 操作导致的.如果存在此情况,请参见 InnerException 以 ...

  3. GSM短信侦听的便宜方案

    侦听GSM短信常用的是OsmocomBB + C118方案,主要是用luca/gsmmap分支.使用ccch_scan这个程序可以把通信封装成GSMTAP发给本机,然后用WireShark接收GSMT ...

  4. Socket基础之-启动异步服务侦听

    Socket网络编程第一篇: 本文主要是以代码为主. .NET技术交流群 199281001 .欢迎加入 1 //负责监听的套接字 private Socket socketServer; //通知一 ...

  5. 如何将数据库引擎配置为侦听多个 TCP 端口

    SQL Server 2005         为 SQL Server 启用 TCP/IP 后,数据库引擎将侦听连接点上是否有传入的连接(由 IP 地址和 TCP 端口号组成).下列步骤将创建一个表 ...

  6. [vue]计算和侦听属性(computed&watch)

    先看一下计算属性 vue只有data区的数据才具备响应式的功能. 计算和侦听属性 - v-text里可以写一些逻辑 <div id="example"> {{ mess ...

  7. Mysql不改默认侦听回环地址而ssh通道连接的办法

    Mysql不改默认侦听回环地址而ssh通道连接的办法 文:铁乐与猫 比较新版的mysql默认侦听的网卡地址是本地回环地址:127.0.0.1: 比如你在/etc/mysql/my.cnf配置文件中往往 ...

  8. 异形Modbus客户端 和 异形modbus服务器之间的通讯 侦听模式的modbus-tcp客户端通讯

    前言 本文将使用一个Github公开的组件技术来实现一个异形ModBus TCP的客户端,方便的对异形Modbus tcp的服务器进行读写,这个服务器可以是电脑端C#设计的,也可以是特殊设备实现的,也 ...

  9. 用VLC读取摄像头产生RTSP流,DSS侦听并转发(二)

    用VLC读取摄像头产生RTSP流,DSS侦听并转发(二) 之前介绍过<用VLC读取摄像头产生RTSP流,DSS主动取流转发(一)>本文介绍另一种方法. 摄像机地址是192.1.101.51 ...

随机推荐

  1. ACM1174_爆头解题思路_空间三维坐标求点到直线的距离

    /* 爆头 Description gameboy是一个CS高手,他最喜欢的就是扮演警察, 手持M4爆土匪的头.也许这里有人没玩过CS,有必 要介绍一下“爆头”这个术语:所谓爆头,就是子 弹直接命中对 ...

  2. nyoj 234 吃土豆

    描述 Bean-eating * grid. Now you want to eat the beans and collect the qualities, but everyone must ob ...

  3. MVC 简单数据传递

    Mode: namespace MVCDemo.Models { public class Data { //申明为静态 归类所有,取数据不要实例化 ; public static string st ...

  4. 修改UISearchBar placeholder textColor

    [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];

  5. Udp实现简单的聊天程序

    在<UDP通讯协议>这篇文章中,简单的说明了Udp协议特征及如何Udp协议传输数据 这里将用Udp协议技术,编写一个简单的聊天程序: //发送端: package com.shindo.j ...

  6. Android声明和使用权限

    Android定义了一种权限方案来保护设备上的资源和功能.例如,在默认情况下,应用程序无法访问联系人列表.拨打电话等.下面就以拨打电话为例介绍一下系统对权限的要求.一般在我们的应用中,如果要用到拨打电 ...

  7. Android——编译odex保护

    编译过android源代码的可能试验过改动编译类型.android的初始化编译配置可參考Android--编译系统初始化设置 一.TARGET_BUILD_VARIANT=user 当选择的编译类型为 ...

  8. Android 打造自己的个性化应用(一):应用程序换肤主流方式的分析与概述

    Android平台api没有特意为换肤提供一套简便的机制,这可能是外国的软件更注重功能和易用,不流行换肤.系统不提供直接支持,只能自行研究. 换肤,可以认为是动态替换资源(文字.颜色.字体大小.图片. ...

  9. js 随手记

    var name = 'frog' function hello(){ alert(name); // undefined var name = 'bbc'; } 在javascript中,函数是可以 ...

  10. java连接sqL2008 数据库实例

    package com.lzw; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSe ...