Here is script, while inspired by Marek, isn't elegant as his are.
But, it works and has been tested against over 100 openvpn config
files from vpngate.
I post the script so that you might make use of it (or improve it).
The script just changes the file name based on IP address, geolocations,
server name, protocol, port, and date (but not speed).
FROM something like:
vpngate_vpn195786088.opengw.net_udp_1195.ovpn
vpngate_vpn805768177.opengw.net_tcp_1841.ovpn
vpngate_114.159.54.159_udp_1942.ovpn
vpngate_78.188.128.102_tcp_16671.ovpn
TO something like:
vpngate_JP_40_Tokyo_Hachioji_119.242.216.189-vpn195786088.opengw.net_udp1195_20160302.ovpn
vpngate_PL_77_Malopolskie_Kraków_83.27.207.198-vpn805768177.opengw.net_tcp1841_20160302.ovpn
vpngate_JP_na_na_na_114.159.54.159-114.159.54.159_udp1942_20160302.ovpn
vpngate_TR_34_Istanbul_Istanbul_78.188.128.102-78.188.128.102_tcp16671_20160302.ovpn
Based on a variety of geolocation lookups of the form:
GeoIP City Edition, Rev 1: can't resolve hostname ( None )
GeoIP City Edition, Rev 1: DE, 15, Thuringen, Tabarz, 99891, 50.883301, 10.516700, 0, 0
GeoIP City Edition, Rev 1: GB, N/A, N/A, N/A, N/A, 51.500000, -0.130000, 0, 0
GeoIP City Edition, Rev 1: HK, 00, N/A, Central District, N/A, 22.283300, 114.150002, 0, 0
GeoIP City Edition, Rev 1: JP, 34, Saitama, Niiza, 352-0006, 35.797901, 139.525406, 0, 0
GeoIP City Edition, Rev 1: JP, 40, Tokyo, Hachioji, 193-0931, 35.655800, 139.323898, 0, 0
GeoIP City Edition, Rev 1: JP, 40, Tokyo, Tokyo, 100-0001, 35.685001, 139.751404, 0, 0
GeoIP City Edition, Rev 1: JP, N/A, N/A, N/A, N/A, 35.689999, 139.690002, 0, 0
GeoIP City Edition, Rev 1: KR, 11, Seoul-t'ukpyolsi, Seoul, N/A, 37.598499, 126.978302, 0, 0
GeoIP City Edition, Rev 1: KR, 13, Kyonggi-do, Suwon, N/A, 37.291100, 127.008904, 0, 0
GeoIP City Edition, Rev 1: KR, N/A, N/A, N/A, N/A, 37.570000, 126.980003, 0, 0
GeoIP City Edition, Rev 1: TR, 34, Istanbul, Istanbul, 34437, 41.037102, 28.986601, 0, 0
GeoIP City Edition, Rev 1: TR, 71, Konya, Konya, 42100, 37.927299, 32.419899, 0, 0
GeoIP City Edition, Rev 1: US, CO, Colorado, Colorado Springs, 80918, 38.914200, -104.774902, 752, 719
GeoIP City Edition, Rev 1: US, MA, Massachusetts, Haverhill, 01835, 42.752998, -71.086098, 506, 978
GeoIP City Edition, Rev 1: US, NH, New Hampshire, Canterbury, 03224, 43.349201, -71.548103, 506, 603
GeoIP City Edition, Rev 1: US, NY, New York, Buffalo, 14221, 42.986401, -78.727898, 514, 716
GeoIP City Edition, Rev 1: US, WI, Wisconsin, Milwaukee, 53202, 43.043400, -87.894501, 617, 414
GeoIP City Edition, Rev 1: VE, N/A, N/A, N/A, N/A, 8.000000, -66.000000, 0, 0
Work in progress will be to add the speedtest, but I am having great
troubles with Marek's too-elegant-for-me-to-understand "sed" method
(mostly my problem is changing Marek's syntax to suit "my" needs)
as shown below:
THIS IS MAREK'S SYNTAX BUT I AM HAVING TROUBLE CHANGING IT:
set -- $(geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $IP)
country="${2/*: /}"
state_abv="${3/' N/A'/na}"
state_long="${4/' N/A'/na}"
city="${5/' N/A'/na}"
zip="${6/' N/A'/na}"
Given I don't "understand" how to change the above syntax, I'll stick
with the "sed,awk,cut" that I've been using to add the speedtest results.
But, until I add the speedtest results, here's the renaming script using
just the country, state, city, IP, servername, protocol, port, & date:
Improvements are always welcome (but I have to be able to *understand*
them sufficient to leverage those improvements further!).
#!/bin/bash
# vpnrename.sh (renames current VPN ovpn file mostly based on geolocation)
# The log below is a 1-line file created only by running "vpntest" where
# vpntest is a modified Marek script that tests a config file by running openvpn.
# When vpntest starts VPN, it puts the full fspec of the ovpn file into the log.
# ---
echo "Getting current ovpn file & date..."
VPN_DATE=$(date +%Y%m%d)
VPN_LOG=/tmp/openvpn.log
VPN_FSPEC=$(cat $VPN_LOG)
VPN_DIR=$(echo $VPN_FSPEC|sed 's%/[^/]*$%/%')
VPN_FILE=$(echo $VPN_FSPEC|sed -e 's/.ovpn$//')
VPN_FNAME=$(echo $VPN_FSPEC|sed -e 's!.*/!!')
VPN_PREFIX=$(echo $VPN_FILE|sed -e 's!.*/!!'|awk -F_ '{print $1}')
# ---
echo "Getting server, protocol, & port..."
SERVER=$(grep ^remote `cat $VPN_LOG`|sed -e 's/
//g'|awk '{print $2}'|sed -e 's/ /-/g')
PROTOCOL=$(grep ^proto `cat $VPN_LOG`|sed -e 's/
//g'|awk -F" " '{print $2}'|sed -e 's/ /-/g')
PORT=$(grep ^remote `cat $VPN_LOG`|sed -e 's/
//g'|awk '{print $3}'|sed -e 's/ /-/g')
# ---
echo "Getting current IP address..."
IP=$(inxi -i |grep IP|awk '{print $5}')
# ---
echo "Getting geolocation information..."
GEO_STRING=$(geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $IP)
GEO_COUNTRY=$(echo $GEO_STRING|awk -F, '{print $2}'|sed -e 's/Rev 1: //' -e 's/ //g'|cut -c 1-2)
GEO_STATE=$(echo $GEO_STRING|awk -F, '{print $3}'|sed -e 's/ //g'|sed -e 's/N\/A/na/')
GEO_LONGSTATE=$(echo $GEO_STRING|awk -F, '{print $4}'|sed -e 's/ //g'|sed -e 's/N\/A/na/'|tr "'" "-")
GEO_CITY=$(echo $GEO_STRING|awk -F, '{print $5}'|sed -e 's/ //g'|sed -e 's/N\/A/na/')
# --
echo "Renaming ovpn file..."
mkdir -p ${VPN_DIR}/renamed
mv $VPN_FSPEC ${VPN_DIR}renamed/${VPN_PREFIX}_${GEO_COUNTRY}_${GEO_STATE}_${GEO_LONGSTATE}_${GEO_CITY}_${IP}-${SERVER}_${PROTOCOL}${PORT}_${VPN_DATE}.ovpn
echo "mv $VPN_FSPEC ${VPN_DIR}renamed/${VPN_PREFIX}_${GEO_COUNTRY}_${GEO_STATE}_${GEO_LONGSTATE}_${GEO_CITY}_${IP}-${SERVER}_${PROTOCOL}${PORT}_${VPN_DATE}.ovpn"
exit 0
## End ##
--- news://
freenews.netfront.net/ - complaints:
ne...@netfront.net ---