• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现扫描局域网活动ip(扫描在线电脑)

Python实现扫描局域网活动ip(扫描在线电脑)

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了python 局域网,python局域网限速,python 局域网扫描,python实现人脸识别,python实现冒泡排序等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

内网的主机都是自动分配ip地址,有时候需要查看下有那些ip在使用,就写了个简单的脚本。
linux和windows下都可以用,用多线程来ping1-255所有的地址,效率不高,2分钟左右。 先凑合和用吧。

#-*- coding: utf-8 -*- 
#author: orangleliu date: 2014-11-12 
#python2.7.x ip_scaner.py 
 
''''' 
不同平台,实现对所在内网端的ip扫描 
 
有时候需要知道所在局域网的有效ip,但是又不想找特定的工具来扫描。 
使用方法 python ip_scaner.py 192.168.1.1 
(会扫描192.168.1.1-255的ip) 
''' 
 
import platform 
import sys 
import os 
import time 
import thread 
 
def get_os(): 
  ''''' 
  get os 类型 
  ''' 
  os = platform.system() 
  if os == "Windows": 
    return "n" 
  else: 
    return "c" 
   
def ping_ip(ip_str): 
  cmd = ["ping", "-{op}".format(op=get_os()), 
      "1", ip_str] 
  output = os.popen(" ".join(cmd)).readlines() 
   
  flag = False 
  for line in list(output): 
    if not line: 
      continue 
    if str(line).upper().find("TTL") >=0: 
      flag = True 
      break 
  if flag: 
    print "ip: %s is ok ***"%ip_str 
 
def find_ip(ip_prefix): 
  ''''' 
  给出当前的127.0.0 ,然后扫描整个段所有地址 
  ''' 
  for i in range(1,256): 
    ip = '%s.%s'%(ip_prefix,i) 
    thread.start_new_thread(ping_ip, (ip,)) 
    time.sleep(0.3) 
   
if __name__ == "__main__": 
  print "start time %s"%time.ctime() 
  commandargs = sys.argv[1:] 
  args = "".join(commandargs)   
   
  ip_prefix = '.'.join(args.split('.')[:-1]) 
  find_ip(ip_prefix) 
  print "end time %s"%time.ctime() 
</div>


是应用的时候: python ip_scaner.py 192.168.31.1 就会扫描 1-255所有的ip地址了。

D:\CodeHouse\python\tools>python ip_scaner.py 10.0.1.38 
start time Wed Nov 12 18:50:58 2014 
ip: 10.0.1.1 is ok *** 
ip: 10.0.1.2 is ok *** 
ip: 10.0.1.24 is ok *** 
ip: 10.0.1.38 is ok *** 
ip: 10.0.1.39 is ok *** 
end time Wed Nov 12 18:52:16 2014 
</div>

就这样。

</div>

您可能想查找下面的文章:

  • Python实现扫描局域网活动ip(扫描在线电脑)

相关文章

  • python列表与元组详解实例
  • python 捕获shell脚本的输出结果实例
  • python列出目录下指定文件与子目录的方法
  • Python bsddb模块操作Berkeley DB数据库介绍
  • 一些Python中的二维数组的操作方法
  • python调用cmd复制文件代码分享
  • 跟老齐学Python之编写类之三子类
  • python基础教程之udp端口扫描
  • Python中条件判断语句的简单使用方法
  • Python简单获取自身外网IP的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 详解Python的Twisted框架中reactor事件管理器的用法
    • python完成FizzBuzzWhizz问题(拉勾网面试题)示例
    • Python的ORM框架中SQLAlchemy库的查询操作的教程
    • 利用Python学习RabbitMQ消息队列
    • Python连接mssql数据库编码问题解决方法
    • python遍历目录的方法小结
    • Python中的异常处理相关语句基础学习笔记
    • python常用知识梳理(必看篇)
    • pygame加载中文名mp3文件出现error
    • Python安装第三方库及常见问题处理方法汇总

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有