Greetings
I'll start from afar. I recently wanted to set up an IPv6 connection via tunnelbroker, but what a bad luck - my ISP gives white dynamic IPv4 addresses, so I need to automate the process of updating the tunnel address. Tunnelbroker itself offers a solution, but it only works on its side, but not on mine, so every time you change the IPv4 address you have to delete the old tunnel and create a new one. Diligently, I found a solution, but I had problems with obtaining an IPv4 address and passing it as an argument to the netsh function. I contacted the author of the code, but he answered a couple of times and calmed down, but the problem did not remain solved. Here, in fact, is the link to the source: http://josherickson.org/132/hurricane-electric-6in4-windows-startup-script/
function fastpingtest { $ping = New-Object System.Net.NetworkInformation.Ping; $ping.Send("8.8.8.8", 1000).status -eq "success"; } $endtime = [datetime]::Now.AddMinutes(1); $mapipv6 = $false; while([datetime]::Now -lt $endtime) { if(fastpingtest) { $mapipv6 = $true; break; } } if($mapipv6) { $wc = New-Object net.webclient; $url= "https://ipv4.tunnelbroker.net/ipv4_end.php?ip=AUTO&pass={1}&apikey={0}&tid={2}"; $values = "USERID", "PASSWORDMD5HASH", TUNNELID; $wc.DownloadString(($url -f $values)); #get connected interface $interface = netsh interface ipv4 show interface | findstr /c:" connected" | ?{!$_.contains("Loopback");} | %{[regex]::Split($_, "( )+") | ?{$_.trim().length -gt 0} | %{$_.trim()}; } $interface_ip = (netsh interface ipv4 show address $interface[0] | findstr /c:"IP Address" | select -First 1).split(":")[1].trim() netsh interface teredo set state disabled netsh interface ipv6 add v6v4tunnel IP6Tunnel $interface_ip HEIPv4ENDPOINT netsh interface ipv6 add address IP6Tunnel YOURIPv6ADDRESS netsh interface ipv6 add route ::/0 IP6Tunnel HEIPv6ADDRESS
The problems begin after the comment. #Get connected interface The author advised to change ! $ .Contains ("Loopback"); on $ .contains ("Satel"); (because my internet connection is so called), I also found it logical to change findstr / c: "IP Address" to findstr / c: "IP Address" , since the original code was written under the English-language system, and I have Russian language . But still, the problem is the same - an incorrect address is written to the $ interface_ip variable (or not recorded at all), the wrong parameters are passed to the netsh command, and nothing works.
Googling the topic of extracting IPv4 addresses, found another option.
#get connected interface $ipAddress = Test-Connection -ComputerName EAGauss -Count 1 | Select -ExpandProperty IPV4Address $interface_ip = $ipAddress.IPAddressToString
Where EAGauss is the name of the host (my computer), I was delighted, because executing these two commands, everything works and my IPv4 address is displayed, but when I replace the old piece of code with this one, I still get the error:
-ERROR: Invalid IPv4 address supplied
What it means is that an invalid parameter is passed to the netsh function.
Please help. Sincerely, EAGauss