HanG321 Blog
Be Shine, Be Smile, Be Wild
  • Home
  • Blog
    • 好文閱讀 readings
    • 生活記事 diary
    • 時事評論 commentary
    • 科技資訊 technology
    • 電腦編程 programming
    • 金融財經 finance
    • 音樂電影 music/movie
  • About

Add route after VPN

August 2, 2014|PowerShell, route, vpn, 網絡資訊|科技資訊, 電腦編程
Home » Blog » 科技資訊 » Add route after VPN
Add route after VPN

For some business reasons, company provides FortiGate SSL VPN to connect office network, but some subnet cannot be accessed due to route did not add automatically.

here is a PowerShell script to find the gateway and interface of VPN connection then add route. It will be great if I can find out how to run script automatically after VPN connection made.

let say office VPN subnet is 10.50.10.0/24, add 2 new subnet by following

add route after SSL VPN
PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# add route required admin right, this will popup and ask for permission.
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
 
# find VPN connection gateway IP and interface number
$vpnroute = Get-WmiObject win32_IP4RouteTable | Where-Object { $_.Destination -eq "10.50.10.0" }
$gateway = $vpnroute.NextHop
$interface = $vpnroute.InterfaceIndex
 
route add 10.50.23.0 mask 255.255.255.0 $gateway metric 20 if $interface
route add 10.60.0.0 mask 255.255.0.0 $gateway metric 20 if $interface

FortiGate SSL VPN client is based on PPP, different to Cisco or others as normal network adapter.

ref:
http://serverfault.com/questions/145259/powershell-win32-networkadapterconfiguration-not-seeing-ppp-adapter
http://stackoverflow.com/questions/3293629/script-for-add-route

photo credit: Brent Hensarling
cc

August 2, 2014 user

Related Posts

  • batch file rename by PowerShell
    batch file rename by PowerShellAugust 3, 2014
  • Upgrade to PowerShell 4.0 on Win 7
    Upgrade to PowerShell 4.0 on Win 7July 30, 2014
  • weekend
    weekendFebruary 1, 2009

Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)June 8, 2015
  • assembly
    assemblyFebruary 11, 2006
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題….October 28, 2004
← Upgrade to PowerShell 4.0 on Win 7
batch file rename by PowerShell →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.




最新文章 Recent Posts

  • Serverless Cloud Run Development: Challenge Lab
  • ionic 4: capacitor & pwa
  • Open file limit of tomcat and mysql in Linux server
  • avoid subquery in mysql update statement
  • hacktoberfest

最新留言 Recent Comments

  • admin on LikeCoin
  • Edmond on LikeCoin
  • John Smith on Install macOS High Sierra on VMware
  • admin on Install macOS High Sierra on VMware
  • nana on Install macOS High Sierra on VMware




熱門文章 Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8) June 8, 2015
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題…. October 28, 2004
  • assembly
    assembly February 11, 2006
  • 新工作
    新工作 January 6, 2009
  • 嫁人要嫁工程師
    嫁人要嫁工程師 April 27, 2006

標籤雲 Tag Cloud

CentOS Character chroot Cluster crash cryptography DD-WRT debug Domino DSM Dual Core DWA email ESXi GCP git google HylaFax IE Java Javascript JRE LikeCoin Linux log LotusScript mint MX MySQL nginx PKI PowerShell Qwiklabs srt telent VMware vpn vSphere WinXP wordpress XPEnology 專欄 網絡資訊 選股 風帆

日曆 Calendar

August 2014
M T W T F S S
  « Jul   Sep »  
 123
45678910
11121314151617
18192021222324
25262728293031

Follow Me

Follow Us on RSSFollow Us on TwitterFollow Us on YouTube

文章存檔 Archives

Copyright © 2004-2021 hang321.net. All Rights Reserved