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
Thank you so much for the script.
ReplyDeleteJust 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
this is the code fixed to work with XP
ReplyDeletedef 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