加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

使用Python得到本机ipv6地址

(2011-11-04 09:00:56)
标签:

使用

python

得到

本机

ipv6

地址

代码

it

分类: 编程语言

# coding=utf-8

import subprocess

import re

   

def get_Local_ipv6_address():

    """

    This function will return your local machine's ipv6 address if it exits.

    If the local machine doesn't have a ipv6 address,then this function return None.

    This function use subprocess to execute command "ipconfig", then get the output

    and use regex to parse it ,trying to  find ipv6 address.

    """

    getIPV6_process = subprocess.Popen("ipconfig", stdout = subprocess.PIPE)

    output = (getIPV6_process.stdout.read())

    ipv6_pattern='(([a-f0-9]{1,4}:){7}[a-f0-9]{1,4})'

    m = re.search(ipv6_pattern, str(output))

    if m is not None:

        return m.group()

    else:

        return None

 

print(get_Local_ipv6_address())

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有