Jump to content
Not connected, Your IP: 3.129.63.252
cla

How to find the AirVpn server IP/name once connected

Recommended Posts

in MacOs using terminal....

To find the IP
dig +short myip.opendns.com @resolver1.opendns.com

To find the server Name
curl -sL https://airvpn.org/client/ | grep "Connected to <strong>" | sed 's/.*<strong>\(.*\)<\/strong>.*/\1/'

 

Share this post


Link to post

For the server's name You might want to check out AirVPN's API:

curl "https://airvpn.org/api/whatismyip/"
Or ipleak's
curl "https://ipleak.net/json/"
Better than "parsing" a web pase.

And as a bonus both of them include your exit ip, but your way is fine when you only need the IP.
 

Share this post


Link to post

Thanks for the kind clue

so updating my previous post

Air_Vpn_ip_Name=`curl -sL https://airvpn.org/api/whatismyip/`

VPN_Name=`echo "$Air_Vpn_ip_Name" |  grep "server_name" | sed 's/    \"server_name\"\: \"//'  |  sed 's/\"\,//'`
VPN_IP=`echo "$Air_Vpn_ip_Name" |  grep '"ip":' | sed 's/    \"ip\"\: \"//'  |  sed 's/\"\,//'`
 

Share this post


Link to post

You are welcome, and thanks for sharing your tricks.

As a last tip, JSON format is fine but if you are going yo extract the info with grep/sed (which I think is fine fine) there is a format option in the API that can make your life easier:

Air_Vpn_ip_Name=`curl -sL https://airvpn.org/api/whatismyip/?format=text`

VPN_Name=`echo "$Air_Vpn_ip_Name" |sed -ne 's/^server_name=//p'`
VPN_IP=`echo "$Air_Vpn_ip_Name" |sed -ne 's/^ip=//p'`

You can check the API tab in the Client Area section of this web, it has a nice API call generator under the name API Explorer which shows all the options and how to use them in a very friendly manner.
 

Share this post


Link to post

JSON output can be processed more elegantly with jq. A simple example:

$ curl -sL https://airvpn.org/api/whatismyip/ | jq .ip,.ipv6
"2003:xxxx:xxxx:xxxx:e36d:c310:da8b:xxxx"
true

The argument to jq is a filter definition with its own programming-like syntax. If invoked without arguments, "." is assumed which takes all output, formats it neatly and colors it. In the filter you can apply a shit ton of actions: maths, sorting, making arrays of outputs, regex, whatever sed would do, etc. are only a few examples. man jq is quite long. :D
 
On 5/25/2020 at 6:29 PM, cla said:

Air_Vpn_ip_Name=`curl -sL https://airvpn.org/api/whatismyip/`

VPN_Name=`echo "$Air_Vpn_ip_Name" |  grep "server_name" | sed 's/    \"server_name\"\: \"//'  |  sed 's/\"\,//'`
VPN_IP=`echo "$Air_Vpn_ip_Name" |  grep '"ip":' | sed 's/    \"ip\"\: \"//'  |  sed 's/\"\,//'`


So this one would be something like:

airvpn_ip_name=`curl -sL https://airvpn.org/api/whatismyip/`

vpn_name=`echo "$airvpn_ip_name"|jq -r .server_name
vpn_ip=`echo $airvpn_ip_name"|jq -r .ip

-r prints fields as strings, in this case, without "" – you avoid calling sed twice that way. :)

NOT AN AIRVPN TEAM MEMBER. USE TICKETS FOR PROFESSIONAL SUPPORT.

LZ1's New User Guide to AirVPN « Plenty of stuff for advanced users, too!

Want to contact me directly? All relevant methods are on my About me page.

Share this post


Link to post

I do actually use jq and with ipleak's API since I got to know it before Airvpns. Didn't suggest it because it needs to be installed and the op seemed to be bound  to grep/sed.
Anyway I didn't know about the -r option to get rid of the "" so thanks a lot @giganerd!! that will save me a lot of |tr -d \" in my scripts!! :)
 

Share this post


Link to post

jq must be installed first, as Mr. eburom noted. :) I believe the way to do that on macOS is via homebrew.


NOT AN AIRVPN TEAM MEMBER. USE TICKETS FOR PROFESSIONAL SUPPORT.

LZ1's New User Guide to AirVPN « Plenty of stuff for advanced users, too!

Want to contact me directly? All relevant methods are on my About me page.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Security Check
    Play CAPTCHA Audio
    Refresh Image

×
×
  • Create New...