CLJ
CLJ

Reputation: 1927

How to detect if a windows machine is running IPV4 or IPV6?

Is there anyway to determine if a windows computer is running IPV6 using native utilities, python or php?

Upvotes: 3

Views: 25964

Answers (5)

CLJ
CLJ

Reputation: 1927

This is how I solved the issue, by trying to open up an IPv6 socket. If the system did not throw an error, then it is using IPv6.

import socket

def isIPV6():   
    ipv6 = True
    try:
        s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    except:
        ipv6 = False
    return ipv6

Upvotes: 6

Steve-o
Steve-o

Reputation: 12866

Enumerate the interfaces and check for an IPv6 address, like everyone else has stated. Alternatives include trying to open an IPv6 socket or get Python to call WSCEnumProtocols()

Upvotes: 1

Filip Dupanović
Filip Dupanović

Reputation: 33690

Jakob's approach is the simplest; you could pipe the result and do a match to see whether a network adapter has a valid IPv6 address.

Additionally, you could get this by fetching the Windows Management Instrumentation class Win32_NetworkAdapterConfiguration. The property IPAddress is an array of all the IP addresses associated with a network adapter and you can match against them to see if there is a IPv6 address associated. But PS is a bit of an overkill, I'd go with Jakob's or Wyatt's answer unless you'd need to do something more intelligible and fancy (send an HTTP request; change some network rules; restart a service).

Upvotes: 0

Wyatt Anderson
Wyatt Anderson

Reputation: 9913

Sure. If ipconfig contains an IPv6 Address entry for a real interface, you've probably got IPv6 connectivity. There are also useful registry entries at HKLM\SYSTEM\CurrentControlSet\services\TCPIP6.

Upvotes: 3

Jakob Bowyer
Jakob Bowyer

Reputation: 34718

Every computer ships with IPv4 at standard. IPv6 is only enabled on specific machines. But if you parse ifconfig/ipconfig then you should find yourself a IPv4/6 address in the output

Upvotes: 1

Related Questions