Hurricane Electric's IPv6 Tunnel Broker Forums

Advanced search  

News:

Welcome to Hurricane Electric's Tunnelbroker.net forums!

Pages: 1 [2] 3

Author Topic: Windows bat file to set up tunnel and Routable prefix.  (Read 12627 times)

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #15 on: March 17, 2014, 08:10:16 AM »

Can you run the following commands in an interactive powershell
Code: [Select]
$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  ???
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #16 on: March 17, 2014, 08:48:07 AM »

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
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #17 on: March 17, 2014, 08:50:24 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).
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #18 on: March 17, 2014, 09:53:23 AM »

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
Code: [Select]
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

Code: [Select]
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
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #19 on: March 17, 2014, 10:07:19 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.
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #20 on: March 17, 2014, 03:27:27 PM »

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

Code: [Select]
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

Code: [Select]
$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $wiredAdapter.ifIndex
to

Code: [Select]
$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex 3
And let me know what happens.

Ravenstar68
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #21 on: March 17, 2014, 04:50:21 PM »


Change the line

Code: [Select]
$ipAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $wiredAdapter.ifIndex
to

Code: [Select]
$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!
« Last Edit: March 17, 2014, 05:12:08 PM by chrisjmartini »
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #22 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.

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

Ravenstar68
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #23 on: March 18, 2014, 06:35:27 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.

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

Win 8.1
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #24 on: March 18, 2014, 06:44:31 AM »

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

(Get-NetAdapter).PhysicalMediaType

Ravenstar
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #25 on: March 18, 2014, 06:46:50 AM »

Can you tell me what output you get from the following.
(Get-NetAdapter).PhysicalMediaType

This is what is returned:

Code: [Select]
Native 802.11
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #26 on: March 18, 2014, 08:05:21 AM »

That's awkward. No wonder the conditional part didn't return anything
Code: [Select]
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.
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #27 on: March 18, 2014, 02:02:33 PM »

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?
Logged

ravenstar

  • Jr. Member
  • **
  • Posts: 63
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #28 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.

Code: [Select]
<#
    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
Logged

chrisjmartini

  • Newbie
  • *
  • Posts: 15
Re: Windows bat file to set up tunnel and Routable prefix.
« Reply #29 on: March 19, 2014, 06:56:04 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).
Logged
Pages: 1 [2] 3