Advertisement
Guest User

e

a guest
May 29th, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. ###################### EDIT YOUR VPN DETAILS BELOW 请先编辑以下内容 #########################
  2.  
  3.  
  4. $VpnName = "VPN" # Connection name, just put anything you like 连线名称随便自己取
  5. $VpnIP = "0.0.0.0" # Enter VPN address displayed 填入网站上显示的PVN位址
  6.  
  7.  
  8. $ConnectNow = 0 # Connect right after creating the connection? 0:No 1:Yes 建立连线后是否开始连接 0:否 1:是
  9. $VpnUsername = "admin" # Enter VPN username displayed (only required if $ConnectNow=1) 填入网站上显示的PVN账号 (如果$ConnectNow=1才要填)
  10. $VpnPassword = "123456" # Enter VPN password displayed (only required if $ConnectNow=1) 填入网站上显示的PVN密码 (如果$ConnectNow=1才要填)
  11.  
  12.  
  13. #############################################################################################
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. $winVer = (Get-WmiObject -class Win32_OperatingSystem).Caption
  22. $winVer
  23. If($winVer -like '*10*'){
  24. Remove-VpnConnection -Name $VpnName -Force -PassThru
  25. Add-VpnConnection -Name "$VpnName" -ServerAddress "$VpnIP" -AuthenticationMethod MSChapv2 -EncryptionLevel Required -TunnelType Pptp -RememberCredential
  26.  
  27. }Else{
  28.  
  29. $PBKFolder = [Environment]::GetEnvironmentVariable("USERPROFILE") + "\AppData\Roaming\Microsoft\Network\Connections\PBK";
  30. $PBKFiles = [Environment]::GetEnvironmentVariable("USERPROFILE") + "\AppData\Roaming\Microsoft\Network\Connections\PBK\rasphone.pbk";
  31. If([System.IO.File]::Exists($PBKFiles)){
  32.  
  33. $newFile = New-Object -TypeName "System.Text.StringBuilder"
  34. [string[]] $file = [System.IO.File]::ReadAllLines($PBKFiles);
  35.  
  36. $atCorrectVPN = 0
  37. $alreadyHaveConnection = 0
  38. $noChange = 0
  39.  
  40.  
  41. Foreach ($line in $file){
  42.  
  43. if ($line -like "[*]")
  44. {
  45. if (($line -eq "[" + $VPNConnectionName + "]")){
  46. $atCorrectVPN = 1;
  47. $alreadyHaveConnection = 1;
  48. }else{
  49. $atCorrectVPN = 1;
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59. if ($line -like "PhoneNumber=*" -and $atCorrectVPN)
  60. {
  61. if ($line -eq "PhoneNumber=$VpnIP")
  62. {
  63. $noChange = 1;
  64. }
  65. else {
  66.  
  67. $newFile.AppendLine("PhoneNumber=$VpnIP");
  68. }
  69.  
  70. }
  71. else
  72. {
  73. $newFile.AppendLine($line);
  74. }
  75.  
  76.  
  77.  
  78. }
  79.  
  80. if ($alreadyHaveConnection -eq 0)
  81. {
  82.  
  83. $rasphone = PBKTEXT $VpnName $VpnIP;
  84. $newRasphone = $rasphone + $newFile.ToString()
  85. [System.IO.File]::WriteAllText($PBKFiles, $newRasphone)
  86.  
  87. }
  88. else
  89. {
  90. if ($noChange -eq 0) {
  91. [System.IO.File]::WriteAllText($PBKFiles, $newFile.ToString())
  92. }
  93. }
  94. }
  95. else
  96. {
  97. $rasphone = PBKTEXT $VpnName $VpnIP;
  98.  
  99. if(![System.IO.Directory]::Exists($PBKFolder)){
  100. [System.IO.Directory]::CreateDirectory($PBKFolder)
  101. }
  102.  
  103. [System.IO.File]::WriteAllText($PBKFiles, $rasphone)
  104.  
  105. }
  106.  
  107. }
  108. If($ConnectNow -eq 1){
  109. & "rasdial.exe" $VpnName $VpnUsername $VpnPassword
  110. }
  111.  
  112. Function PBKTEXT
  113. {
  114. Param([string] $name, [string] $ip)
  115. $guid = [guid]::NewGuid()
  116. $data = "[$name]
  117. Encoding=1
  118. PBVersion=1
  119. Type=2
  120. AutoLogon=0
  121. UseRasCredentials=1
  122. LowDateTime=-807177520
  123. HighDateTime=30658994
  124. DialParamsUID=46099356
  125. Guid=$guid
  126. VpnStrategy=1
  127. ExcludedProtocols=0
  128. LcpExtensions=1
  129. DataEncryption=256
  130. SwCompression=0
  131. NegotiateMultilinkAlways=0
  132. SkipDoubleDialDialog=0
  133. DialMode=0
  134. OverridePref=15
  135. RedialAttempts=3
  136. RedialSeconds=60
  137. IdleDisconnectSeconds=0
  138. RedialOnLinkFailure=1
  139. CallbackMode=0
  140. CustomDialDll=
  141. CustomDialFunc=
  142. CustomRasDialDll=
  143. ForceSecureCompartment=0
  144. DisableIKENameEkuCheck=0
  145. AuthenticateServer=0
  146. ShareMsFilePrint=1
  147. BindMsNetClient=1
  148. SharedPhoneNumbers=0
  149. GlobalDeviceSettings=0
  150. PrerequisiteEntry=
  151. PrerequisitePbk=
  152. PreferredPort=VPN3-0
  153. PreferredDevice=WAN Miniport (PPTP)
  154. PreferredBps=0
  155. PreferredHwFlow=1
  156. PreferredProtocol=1
  157. PreferredCompression=1
  158. PreferredSpeaker=1
  159. PreferredMdmProtocol=0
  160. PreviewUserPw=1
  161. PreviewDomain=1
  162. PreviewPhoneNumber=0
  163. ShowDialingProgress=1
  164. ShowMonitorIconInTaskBar=1
  165. CustomAuthKey=0
  166. AuthRestrictions=512
  167. IpPrioritizeRemote=1
  168. IpInterfaceMetric=0
  169. IpHeaderCompression=0
  170. IpAddress=0.0.0.0
  171. IpDnsAddress=0.0.0.0
  172. IpDns2Address=0.0.0.0
  173. IpWinsAddress=0.0.0.0
  174. IpWins2Address=0.0.0.0
  175. IpAssign=1
  176. IpNameAssign=1
  177. IpDnsFlags=0
  178. IpNBTFlags=1
  179. TcpWindowSize=0
  180. UseFlags=2
  181. IpSecFlags=0
  182. IpDnsSuffix=
  183. Ipv6Assign=1
  184. Ipv6Address=::
  185. Ipv6PrefixLength=0
  186. Ipv6PrioritizeRemote=1
  187. Ipv6InterfaceMetric=0
  188. Ipv6NameAssign=1
  189. Ipv6DnsAddress=::
  190. Ipv6Dns2Address=::
  191. Ipv6Prefix=0000000000000000
  192. Ipv6InterfaceId=0000000000000000
  193. DisableClassBasedDefaultRoute=0
  194. DisableMobility=0
  195. NetworkOutageTime=0
  196. ProvisionType=0
  197. PreSharedKey=
  198.  
  199. NETCOMPONENTS=
  200. ms_msclient=1
  201. ms_server=1
  202.  
  203. MEDIA=rastapi
  204. Port=VPN3-0
  205. Device=WAN Miniport (PPTP)
  206.  
  207. DEVICE=vpn
  208. PhoneNumber=$ip
  209. AreaCode=
  210. CountryCode=0
  211. CountryID=0
  212. UseDialingRules=0
  213. Comment=
  214. FriendlyName=
  215. LastSelectedPhone=0
  216. PromoteAlternates=0
  217. TryNextAlternateOnFail=1
  218. "
  219. return $data
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement