• Welcome to Hurricane Electric's IPv6 Tunnel Broker Forums.

Windows bat file to set up tunnel and Routable prefix.

Started by ravenstar, March 05, 2014, 12:07:44 PM

Previous topic - Next topic

chrisjmartini

Quote from: ravenstar on March 17, 2014, 07:44:51 AM
Can you run the following commands in an interactive powershell
$wiredAdapter = Get-NetAdapter | Where-Object {$_.PhysicalMediaType -eq '802.3'}
$wiredAdapter


Line 29 relies on the outcome of these 2 lines.

I have run these, but nothing happens  ???

ravenstar

Strange - I am using the same version of powershell

Here's what you should be getting

PS C:\Users\Timothy> $wiredAdapter = Get-NetAdapter | Where-Object {$_.PhysicalMediaType -eq '802.3'}

PS C:\Users\Timothy> $wiredAdapter

Name                      InterfaceDescription                    ifIndex Status 
----                      --------------------                    ------- ------ 
Ethernet                  Qualcomm Atheros AR8131 PCI-E Gigabi...       3 Up

You do have an ethernet adapter? lol

Ravenstar

chrisjmartini

Quote from: ravenstar on March 17, 2014, 08:48:07 AM
Strange - I am using the same version of powershell

You do have an ethernet adapter? lol

Ravenstar

HeHe, yes I have one indeed. In fact it's the same one as you (Atheros 8131).

ravenstar

That should be working

The first line simply uses Get-NetAdapter which lists all the Network Adapters on the system
but pipes the output through the Where-Object Cmdlet to output only the ethernet adapters, and stores the  in the $wiredAdapter variable.

I did find a code snippet that was supposed to do the trick but I found the Wireless adapters were being enumerated as well so I had to come up with my own method.

Here's what I get from the command line without using the $wiredAdapter variable
PS C:\Users\Timothy> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
WiFi 3                    Atheros AR5007UG Wireless Network Ad...      13 Disconnected 00-1D-0F-B1-82-B9          0 bps
Ethernet                  Qualcomm Atheros AR8131 PCI-E Gigabi...       3 Up           F4-6D-04-3B-22-78       100 Mbps


And after applying the filter

PS C:\Users\Timothy> Get-NetAdapter | Where-Object {$_.PhysicalMediaType -eq '802.3'}

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Qualcomm Atheros AR8131 PCI-E Gigabi...       3 Up           F4-6D-04-3B-22-78       100 Mbps


You are using Curly braces around the expression after the Where-Object?

The reason I ask is because it's caught me out too.

Ravenstar68

chrisjmartini

Quote from: ravenstar on March 17, 2014, 09:53:23 AM

You are using Curly braces around the expression after the Where-Object?

The reason I ask is because it's caught me out too.

Yes, I have copy/pasted your commands exactly. I have just tried the above using an elevated PowerShell ISE. Screenshot attached with result. Get-NetAdapter with no arguments returns a listing of all adapters, real and virtual. The same command with arguments returns nothing.

ravenstar

It's strange - line should work.

The section following the Get-NetAdapter isn't an argument - it's a pipe - it tells the system to redirect the output - in this instance through the Where-Object Cmdlet.  It could just as easily redirect the output to a file for example if I change it to

Get-NetAdapter | Out-File E:\netadapter.txt

It would simply pipe the output through Out-File Cmdlet and store it in E:\netadapter.txt (Note unless you#re running in administrator mode don't try C:\netadapter.txt as it will give an access violation.

We can edit the next line however to manually include the Interface Index of the Ethernet Adapter. (Yours is the same as mine if.index = 3)  While not ideal it should at least get the script working on your system.

Change the line

$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $wiredAdapter.ifIndex

to

$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex 3

And let me know what happens.

Ravenstar68

chrisjmartini

#21
Quote from: ravenstar on March 17, 2014, 03:27:27 PM

Change the line

$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $wiredAdapter.ifIndex

to

$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex 3

And let me know what happens.

I have now done this and did get further :) Two 'ok's and three 'element not found'  See screenshot.

UPDATE: It appears this has worked despite what the ouput states. I now have access to ipv6 addresses!

Many thanks for this great bat file Ravenstar68!

ravenstar

It's still not right for you - It's not picked up the Network adapter name hence some of the element not found messages. :(

This means you have the basic Tunnel on the one PC but the route is not being shared across your network properly.

Out of interest what version of windows do you have?  I am running 8.1

Ravenstar68

chrisjmartini

Quote from: ravenstar on March 18, 2014, 05:36:32 AM
It's still not right for you - It's not picked up the Network adapter name hence some of the element not found messages. :(

This means you have the basic Tunnel on the one PC but the route is not being shared across your network properly.

Ah ok, this explains why after the tunnel was created, the rest of the machines on the network (a google tv, laptop and two phones) experienced a total slow down on the connection. Once I removed the tunnel, restarted my laptop and the modem, things returned to normal.

Quote from: ravenstar on March 18, 2014, 05:36:32 AM
Out of interest what version of windows do you have?  I am running 8.1

Win 8.1

ravenstar

Can you tell me what output you get from the following.

(Get-NetAdapter).PhysicalMediaType

Ravenstar

chrisjmartini

Quote from: ravenstar on March 18, 2014, 06:44:31 AM
Can you tell me what output you get from the following.
(Get-NetAdapter).PhysicalMediaType

This is what is returned:

Native 802.11
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified

ravenstar

That's awkward. No wonder the conditional part didn't return anything
PS C:\Users\Timothy> (Get-NetAdapter).PhysicalMediaType
Native 802.11
802.3
PS C:\Users\Timothy>



The only other thing I can think of doing is Enumerating all the adapters and letting you pick the Ethernet adapter out from the list :(

So far the only other solution I've seen to work out which was a LAN adapter didn't work for me as it also listed the Wireless Adapters.  You'd have thought they'd meet a common standard lol.

chrisjmartini

I really only need the ipv6 tunnel for the one machine. Is it possible to have this without affecting the other machines on the network?

ravenstar

Basic Tunnel is easy  ;)  All you have to do is strip out the last section of the code

However here's the full cut down script removing any variable checks that aren't needed.

<#
    Pwershell Script to automate setting up a HE.net IPv6 Tunnel
    Copyright (C) 2014 Timothy Dutton
#>


cd $PSScriptRoot
# Script needs administrator priviledges to run the Netsh coammnds correctly
# So check to see if we are already running as such
. .\Elevate.ps1
. .\GetTunnelInfo.ps1
Elevate

# Have already created a function GetTunnelInfo which prompts for a username and password
# And then connects to Tunnelbroker.net and gets the first tunnel found using their API
$ErrorActionPreference = "Stop"
$tunnel = Get-TunnelInfo

# Strip out the info we need to create the tunnel.  While not necessary it makes the
# netsh commands further down easier to read
$serverv4=$tunnel.serverv4
$clientv6=$tunnel.clientv6
$serverv6=$tunnel.serverv6

# Before setting up the Tunnel Display the Values
Write-Host "Client IPv4 Address is $($clientv4)"
Write-Host "Server IPv4 Address is $($serverv4)"
Write-Host "Client IPv6 Address is $($clientv6)"
Write-Host "Server IPv6 Address is $($serverv6)"
# Now we wait for user to press enter
Read-Host "Press Enter to set up tunnel or CTRL-C to abort"

# Now set up the basic tunnel
netsh int ipv6 add v6v4tunnel IP6Tunnel $clientv4 $serverv4
netsh int ipv6 add address IP6Tunnel $clientv6
netsh int ipv6 add route ::/0 IP6Tunnel $serverv6


Save it in the same folder as it still uses Get-TunnelInfo and Elevate.

That should give you basic IPv6 access for one machine.

Ravenstar

chrisjmartini

Quote from: ravenstar on March 19, 2014, 05:53:09 AM
Basic Tunnel is easy  ;)  All you have to do is strip out the last section of the code

However here's the full cut down script removing any variable checks that aren't needed.

Save it in the same folder as it still uses Get-TunnelInfo and Elevate.

That should give you basic IPv6 access for one machine.

Thanks. Though it seems maybe too much was removed? Now the script is not grabbing the client ipv4 address (attached).