Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Programmatically changing OpenVPN client server IP?

    Scheduled Pinned Locked Moved OpenVPN
    3 Posts 2 Posters 909 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      CapitanBlack
      last edited by CapitanBlack

      I've created a one-liner script which returns the least loaded ProtonVPN Plus server for an ISO country code.

      !/bin/sh
      
      # Returns IP address of the least loaded server for any country
      # Requires 2-letter ISO country code as the first parameter
      # If country code is missing or not found - returns null string
      
      curl -s https://api.protonmail.ch/vpn/logicals | jq "[.LogicalServers[]|select(.Name|contains(\"$1\"))|select(.Tier==2)|{ServerName: .Name, ServerLoad: (.Load|tonumber),EntryIP: .S
      ervers[].EntryIP}] | sort_by(.ServerLoad)" | jq -r '.[0].EntryIP'
      

      Example:

      [2.6.0-RELEASE][root@inf-pfsense-01]/root/bin: ./proton.sh UK
      146.70.96.66
      

      Is there any way to programmatically change server IP for an OpenVPN client #X?

      The client restart command is here:

      #!/bin/sh
      /usr/local/sbin/pfSsh.php playback svc restart openvpn client 1
      
      GertjanG 1 Reply Last reply Reply Quote 0
      • GertjanG Offline
        Gertjan @CapitanBlack
        last edited by Gertjan

        @capitanblack said in Programmatically changing OpenVPN client server IP?:

        146.70.96.xx

        Is that the IP proton gave you ?
        If so, then no, not possible. They own a pool with addresses per VPN server, and attribute one to you.

        edit : disconnect, and reconnect,might work ?

        No "help me" PM's please. Use the forum, the community will thank you.
        Edit : and where are the logs ??

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          CapitanBlack @Gertjan
          last edited by CapitanBlack

          @gertjan
          You should try how the script works. It returns IP address of the LEAST loaded server in a country at this moment . The idea I have is to use cron to stop VPN client every 15 minutes, get the least loaded server IP, change it in pfSense OpenVPN client config and start the client. This way my pfSense will be "always" connected to the fastest server in a specific country.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.