windowswinapipywin32ras

I want to connect a windows machine to a L2TP/ IPsec vpn using python


I have a soft-ether VPN server and I want to make a custom client application, which will look like other vpn clients (Nord,Hola vpns) in python. The problem is in python I cannot find a way to use windows built-in vpn manager to connect via IPsec protocol programmatically.

In C I can find a RAS API but since I am new to network infrastructure programming so its hard for me to dissolve it properly uderstand how it actually works.


Solution

  • You can use Add-VpnConnection and Set-VpnConnectionIPsecConfigurationin Windows PowerShell

    See the Example 2 in 2nd link:

    PS C:\> Add-VpnConnection -Name "Contoso" -ServerAddress 176.16.1.2 -TunnelType "L2tp"
    PS C:\> Set-VpnConnectionIPsecConfiguration -ConnectionName "Contoso" -AuthenticationTransformConstants None -CipherTransformConstants AES128 -EncryptionMethod AES128 -IntegrityCheckMethod SHA256 -PfsGroup None -DHGroup ECP256 -PassThru -Force
    AuthenticationTransformConstants : None
    
    CipherTransformConstants         : AES128
    
    DHGroup                          : ECP256
    
    IntegrityCheckMethod             : SHA256
    
    PfsGroup                         : None
    
    EncryptionMethod                 : AES128
    

    And it should also be simple to call the PowerShell from Python.