Python3之读取连接过的网络并定位的方法

yipeiwu_com6年前Python基础

如下所示:

#!/usr/bin/python
# coding=utf-8
import json
from urllib.request import urlopen
from winreg import *
def val2addr(val):
 addr = ""
 for ch in val:
  addr += ("%02x " % ord(ch))
 addr = addr.strip(" ").replace(" ", ":")[0:17]
 return addr
def printNets():
 net = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged"
 key = OpenKey(HKEY_LOCAL_MACHINE, net)
 print(r"\nNetworks You have Joined.")
 for i in range(100):
  try:
   guid = EnumKey(key, i)
   netKey = OpenKey(key, str(guid))
   (n, addr, t) = EnumValue(netKey, 5)
   (n, name, t) = EnumValue(netKey, 4)
   macAddr = val2addr(addr)
   netName = name
   jsondata = urlopen('http://api.cellocation.com:81/wifi/?mac=' + macAddr + '&output=json').read()
   data = json.loads(jsondata)['address']
   if data == '':
    address = 'unknow'
   else:
    address = data
   print('[+] ' + netName + ' ' + macAddr + ' ' + address)
   CloseKey(netKey)
  except:
   break
def main():
 printNets()
 input('please press enter')
if __name__ == '__main__':
 main()

内置模块:

python2中的_winreg在python3中改名为winreg!!!

以上这篇Python3之读取连接过的网络并定位的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

pyspark.sql.DataFrame与pandas.DataFrame之间的相互转换实例

pyspark.sql.DataFrame与pandas.DataFrame之间的相互转换实例

代码如下,步骤流程在代码注释中可见: # -*- coding: utf-8 -*- import pandas as pd from pyspark.sql import Spar...

python微元法计算函数曲线长度的方法

python微元法计算函数曲线长度的方法

计算曲线长度,根据线积分公式: ,令积分函数 f(x,y,z) 为1,即计算曲线的长度,将其微元化: 其中 根据此时便可在python编程实现,给出4个例子,代码中已有详细注释,不...

SublimeText 2编译python出错的解决方法(The system cannot find the file specified)

[Error 2] The system cannot find the file specified 解决方法:1.环境变量path添加:C:\Python32\Tools\Scrip...

python 捕获shell脚本的输出结果实例

import subprocess output =Popen(["mycmd","myarg"], stdout=PIPE).communicate()[0] import subp...

使用Py2Exe for Python3创建自己的exe程序示例

使用Py2Exe for Python3创建自己的exe程序示例

最近使用Python 3.5写了一个GUI小程序,于是想将该写好的程序发布成一个exe文件,供自己单独使用。至于通过安装的方式使用该程序,我没有探索,感兴趣的读者可以自己摸索。 1 介绍...