Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################### EDIT YOUR VPN DETAILS BELOW 请先编辑以下内容 #########################
- $VpnName = "VPN" # Connection name, just put anything you like 连线名称随便自己取
- $VpnIP = "0.0.0.0" # Enter VPN address displayed 填入网站上显示的PVN位址
- $ConnectNow = 0 # Connect right after creating the connection? 0:No 1:Yes 建立连线后是否开始连接 0:否 1:是
- $VpnUsername = "admin" # Enter VPN username displayed (only required if $ConnectNow=1) 填入网站上显示的PVN账号 (如果$ConnectNow=1才要填)
- $VpnPassword = "123456" # Enter VPN password displayed (only required if $ConnectNow=1) 填入网站上显示的PVN密码 (如果$ConnectNow=1才要填)
- #############################################################################################
- $winVer = (Get-WmiObject -class Win32_OperatingSystem).Caption
- $winVer
- If($winVer -like '*10*'){
- Remove-VpnConnection -Name $VpnName -Force -PassThru
- Add-VpnConnection -Name "$VpnName" -ServerAddress "$VpnIP" -AuthenticationMethod MSChapv2 -EncryptionLevel Required -TunnelType Pptp -RememberCredential
- }Else{
- $PBKFolder = [Environment]::GetEnvironmentVariable("USERPROFILE") + "\AppData\Roaming\Microsoft\Network\Connections\PBK";
- $PBKFiles = [Environment]::GetEnvironmentVariable("USERPROFILE") + "\AppData\Roaming\Microsoft\Network\Connections\PBK\rasphone.pbk";
- If([System.IO.File]::Exists($PBKFiles)){
- $newFile = New-Object -TypeName "System.Text.StringBuilder"
- [string[]] $file = [System.IO.File]::ReadAllLines($PBKFiles);
- $atCorrectVPN = 0
- $alreadyHaveConnection = 0
- $noChange = 0
- Foreach ($line in $file){
- if ($line -like "[*]")
- {
- if (($line -eq "[" + $VPNConnectionName + "]")){
- $atCorrectVPN = 1;
- $alreadyHaveConnection = 1;
- }else{
- $atCorrectVPN = 1;
- }
- }
- if ($line -like "PhoneNumber=*" -and $atCorrectVPN)
- {
- if ($line -eq "PhoneNumber=$VpnIP")
- {
- $noChange = 1;
- }
- else {
- $newFile.AppendLine("PhoneNumber=$VpnIP");
- }
- }
- else
- {
- $newFile.AppendLine($line);
- }
- }
- if ($alreadyHaveConnection -eq 0)
- {
- $rasphone = PBKTEXT $VpnName $VpnIP;
- $newRasphone = $rasphone + $newFile.ToString()
- [System.IO.File]::WriteAllText($PBKFiles, $newRasphone)
- }
- else
- {
- if ($noChange -eq 0) {
- [System.IO.File]::WriteAllText($PBKFiles, $newFile.ToString())
- }
- }
- }
- else
- {
- $rasphone = PBKTEXT $VpnName $VpnIP;
- if(![System.IO.Directory]::Exists($PBKFolder)){
- [System.IO.Directory]::CreateDirectory($PBKFolder)
- }
- [System.IO.File]::WriteAllText($PBKFiles, $rasphone)
- }
- }
- If($ConnectNow -eq 1){
- & "rasdial.exe" $VpnName $VpnUsername $VpnPassword
- }
- Function PBKTEXT
- {
- Param([string] $name, [string] $ip)
- $guid = [guid]::NewGuid()
- $data = "[$name]
- Encoding=1
- PBVersion=1
- Type=2
- AutoLogon=0
- UseRasCredentials=1
- LowDateTime=-807177520
- HighDateTime=30658994
- DialParamsUID=46099356
- Guid=$guid
- VpnStrategy=1
- ExcludedProtocols=0
- LcpExtensions=1
- DataEncryption=256
- SwCompression=0
- NegotiateMultilinkAlways=0
- SkipDoubleDialDialog=0
- DialMode=0
- OverridePref=15
- RedialAttempts=3
- RedialSeconds=60
- IdleDisconnectSeconds=0
- RedialOnLinkFailure=1
- CallbackMode=0
- CustomDialDll=
- CustomDialFunc=
- CustomRasDialDll=
- ForceSecureCompartment=0
- DisableIKENameEkuCheck=0
- AuthenticateServer=0
- ShareMsFilePrint=1
- BindMsNetClient=1
- SharedPhoneNumbers=0
- GlobalDeviceSettings=0
- PrerequisiteEntry=
- PrerequisitePbk=
- PreferredPort=VPN3-0
- PreferredDevice=WAN Miniport (PPTP)
- PreferredBps=0
- PreferredHwFlow=1
- PreferredProtocol=1
- PreferredCompression=1
- PreferredSpeaker=1
- PreferredMdmProtocol=0
- PreviewUserPw=1
- PreviewDomain=1
- PreviewPhoneNumber=0
- ShowDialingProgress=1
- ShowMonitorIconInTaskBar=1
- CustomAuthKey=0
- AuthRestrictions=512
- IpPrioritizeRemote=1
- IpInterfaceMetric=0
- IpHeaderCompression=0
- IpAddress=0.0.0.0
- IpDnsAddress=0.0.0.0
- IpDns2Address=0.0.0.0
- IpWinsAddress=0.0.0.0
- IpWins2Address=0.0.0.0
- IpAssign=1
- IpNameAssign=1
- IpDnsFlags=0
- IpNBTFlags=1
- TcpWindowSize=0
- UseFlags=2
- IpSecFlags=0
- IpDnsSuffix=
- Ipv6Assign=1
- Ipv6Address=::
- Ipv6PrefixLength=0
- Ipv6PrioritizeRemote=1
- Ipv6InterfaceMetric=0
- Ipv6NameAssign=1
- Ipv6DnsAddress=::
- Ipv6Dns2Address=::
- Ipv6Prefix=0000000000000000
- Ipv6InterfaceId=0000000000000000
- DisableClassBasedDefaultRoute=0
- DisableMobility=0
- NetworkOutageTime=0
- ProvisionType=0
- PreSharedKey=
- NETCOMPONENTS=
- ms_msclient=1
- ms_server=1
- MEDIA=rastapi
- Port=VPN3-0
- Device=WAN Miniport (PPTP)
- DEVICE=vpn
- PhoneNumber=$ip
- AreaCode=
- CountryCode=0
- CountryID=0
- UseDialingRules=0
- Comment=
- FriendlyName=
- LastSelectedPhone=0
- PromoteAlternates=0
- TryNextAlternateOnFail=1
- "
- return $data
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement