How to set static IPv6 address programmatically under Windows 7
-
Monday, November 19, 2012 12:18 PM
Hello,
Please help me to set a static IPv6 address programmatically under Windows 7. The program is in C++, but a solution in some other language will suite as well. I tried using WMI EnableStatic, and that works fine for IPv4, but for IPv6 address it returns error 70 (Invalid IP address). In particular, this error is returned for the address, which is returned as a property of Win32_NetworkAdapterConfiguration - fe80::8414:30e:d2d8:499c. It is also not clear what to specify as Subnet Mask in case of IPv6 - should it be fe80::/64, or something else?
Thanks.
All Replies
-
Wednesday, February 20, 2013 2:25 PMIve been fighting with this too. WMI allows you to view IPv6 addresses but not set them. You can use the command line to modify ipv6 using netsh (Do a google search on it) but I like WMI MUC H better and am hoping they support it soon
-
Wednesday, March 06, 2013 6:13 AMAre there any Microsoft official answers? Is there any way to add IPv6 adapter adresses programmatically (WinAPI or WMI)?
-
Wednesday, March 13, 2013 7:00 PM
From what I can gather it is not possible to set (just to read) due to limits in implementation http://msdn.microsoft.com/en-us/library/aa822883(v=vs.85).aspx
Perhaps use NETSH.EXE launched from your app? or, as I would recomend invoking the PowerShell Runtime and make it in PowerShell where it is implemented. That also gives loads of other possibilities for your app.
Another alternative that could be a way to go is to open NETSH.EXE and check with dependency walker on how that tool sets adresses..
-
Wednesday, March 13, 2013 7:07 PM
Ok; couldn't keep my hands out of the cookie jar. Seems to be in iphlpapi.dll.. very poor documentation however..
-
Friday, April 05, 2013 4:16 AMOwner
Not super helpful necessarily, but in Windows 8/Server 2012, this can be trivially done using the new PowerShell/WMI functionality. (Get-NetIPAddress, New-NetIPAddress, etc).
In Windows 7 and such it's harder, the IP helper API is the place to start but there are considerable limitations.
-
Saturday, April 27, 2013 3:24 AM
You will need PowerShell version 3.0 (included in the Windows Management Framework Core 3.0) for Windows 7 Service Pack 1. You can download that from here:
http://www.microsoft.com/en-us/download/details.aspx?id=34595
After installing PowerShell v3.0, you will want to make sure that you update your internal documentation by launching PowerShell "as Administrator" and running the command: Update-Help -Force;
Now that you've got PowerShell 3.0 installed, and your documentation updated, you will need to figure out which interface index (or interface name) you want to add an IPv6 address to. You can do this using the Get-NetAdapter cmdlet in PowerShell v3. I am not positive if this command is available on Windows 7, but it's worth a try. When you run that command, with no parameters, you will be presented a list of network interfaces (both physical and virtual) on your local system, along with the corresponding interface index. Take note of the interface index you want to add an IPv6 address to.
Now that you know which interface index you want to modify, run a command similar to the one below, to add a static IPv6 address to the interface. It's important to note that the documentation for Set-NetIPAddress explicitly states that, once an IP address is created, you cannot modify the IP address. Therefore, if you mess up the IP address when you add it using New-NetIPAddress, you must Remove-NetIPAddress, rather than amending the address using Set-NetIPAddress.
New-NetIPAddress -InterfaceIndex 28 -IPAddress 2702:2702:2702:2702:2702:2702:2702:2702 -AddressFamily IPv6 -Type Unicast -PrefixLength 64;
I hope this helps!
If this post was helpful, please click the little "Vote as Helpful" button :)
Trevor Sullivan
Trevor Sullivan's Tech Room
Twitter Profile- Edited by Trevor Sullivan Saturday, April 27, 2013 3:24 AM

