cla 3 Posted ... in MacOs using terminal....To find the IP dig +short myip.opendns.com @resolver1.opendns.comTo find the server Name curl -sL https://airvpn.org/client/ | grep "Connected to <strong>" | sed 's/.*<strong>\(.*\)<\/strong>.*/\1/' Quote Share this post Link to post
eburom 16 Posted ... 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. Quote Share this post Link to post
cla 3 Posted ... 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/\"\,//'` Quote Share this post Link to post
eburom 16 Posted ... 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. Quote Share this post Link to post
OpenSourcerer 1435 Posted ... 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. 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. 1 eburom reacted to this Quote Hide OpenSourcerer's signature Hide all signatures 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
eburom 16 Posted ... 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!! 1 OpenSourcerer reacted to this Quote Share this post Link to post
cla 3 Posted ... doing curl -sL https://airvpn.org/api/whatismyip/ | jq .ip,.ipv6 On MacOs 10.14.6 (Mojave) I receive a jq: command not found Quote Share this post Link to post
OpenSourcerer 1435 Posted ... jq must be installed first, as Mr. eburom noted. I believe the way to do that on macOS is via homebrew. Quote Hide OpenSourcerer's signature Hide all signatures 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