Getting IPv4 address and using it as an argument for netsh function

About a week ago I decided to set up the IPv6 connection via tunnelbroker but my ISP gives only dynamic dedicated IPv4 addresses. The tunnelbroker gives a solution to update the dynamic IPv4 address but it works only on server side. It means that every time my IPv4 address changes, I need to delete the old tunnel and create a new one.
I've found a solution, the Powershsell 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 disablednetsh interface ipv6 add v6v4tunnel IP6Tunnel $interface_ip HEIPv4ENDPOINTnetsh interface ipv6 add address IP6Tunnel YOURIPv6ADDRESSnetsh interface ipv6 add route ::/0 IP6Tunnel HEIPv6ADDRESS


But it didn't work the problem starts from #get connected interface
comment. I contacted the Author and he adviced me to replace !$.contains("Loopback"); with $.contains("Satel"); (name of my Internet connection) and also I decided to replace findstr /c:"IP Address" with findstr /c:"IP-" (because I have a russian version of Windows 7).
Anyway the problem is that $interface_ip gets wring value and netsh command gives an error:
-ERROR: Invalid IPv4 address supplied
Then I've found another way to get the IPv4 address:

#get connected interface$ipAddress = Test-Connection -ComputerName EAGauss -Count 1 | Select -ExpandProperty IPV4Address$interface_ip = $ipAddress.IPAddressToString


Where EAGauss is my hostname. It worked separately from the code but when I tried to change old strings to the new ones it gave the same error.
-ERROR: Invalid IPv4 address supplied

I'm waiting for your help.
Regards,
EAGauss

August 30th, 2015 2:50am

Emile - you need to repost your code as it has lost al formatting and is unreadable.

You also need to have the author of the script fix it for you.  We don't fix code found on the Internet  We can answer any specific question you may want to ask.

Free Windows Admin Tool Kit Click here and download it now
August 30th, 2015 6:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics