Skip to content

Instantly share code, notes, and snippets.

@smzm
Last active July 27, 2024 14:15
Show Gist options
  • Save smzm/3661877890d6740e81e9f4de1eb2dcdd to your computer and use it in GitHub Desktop.
Save smzm/3661877890d6740e81e9f4de1eb2dcdd to your computer and use it in GitHub Desktop.
Replace IP adresses with domain in openvpn files

Prerequisites

  • ack
  • sed
  • dig

Install prerequisites

  • Arch : sudo pacman -S ack bind
  • Ubuntu : sudo apt install dnsutils ack sed
  • MacOS : brew install ack bind

Usage

1. Create a file and named something like : ovpn-resolver.sh

And put these lines inside it :

#!/bin/bash

DOMAIN=`cat $1 | awk '/remote / {print $2}'`
DIG=$(dig $DOMAIN +short)
IP=`echo "$DIG" | awk '{print "remote " $0}'`

EXTRACT_NAME=`echo $1 | awk 'BEGIN{FS="/"} {print $NF}' | awk 'BEGIN{FS="."} {print $1}'`

cat $1 | sed "/^remote /a ${IP//$'\n'/\\n}" | sed "s/^remote[[:blank:]][a-z]/# &/" > $EXTRACT_NAME-ip.ovpn

2. Run chmod +x ovpn-resolver.sh


3. At the end run the script :

./ovpn-resolver.sh YOUR-OPENVPN-FILE.ovpn

Replace YOUR-OPENVPN-FILE.ovpn with your ovpn config file


Now you have a file with the name [YOUR-OPENVPN-FILE]-ip.ovpn which replaced domain with ip adresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment