Tuesday, January 4, 2011

Find IPv6 address on windows

import os
f=os.popen("ipconfig").read()
z=f.split()
has_ipv6 = False
ip6=""
for i in range(len(z)):
    if z[i]=='IPv6':
        has_ipv6 = True
    if has_ipv6:
        if len(z[i])>20:
            if z[i].find('::')>0:
                ip6=z[i]
                break

2 comments:

  1. Thank you so much for the script.

    Just wanted to comment that it works fine for Windows Vista and Windows 7, but fails on Windows XP and 2003, because they don't distinguish IPv4 and IPv6 on the ipconfig command

    ReplyDelete
  2. this is the code fixed to work with XP

    def get_ipv6():
    '''Returns the IPv6 address of a windows machine'''
    f=os.popen("ipconfig").read()
    z=f.split()
    has_ipv6 = False
    ip6=""
    for i in range( len(z) ):
    if z[i]=='IP': #for XP compatibility
    has_ipv6 = True
    if has_ipv6:
    if len(z[i]) > 25:
    if '::' not in z[i]: #check if it is not localhost IPv6 address
    ip6=z[i]
    break
    return ip6

    ReplyDelete