Skip to content

Instantly share code, notes, and snippets.

@krishnachaitanya7
Last active August 24, 2021 22:16
Show Gist options
  • Save krishnachaitanya7/bc42b4e799dfeff3ec92 to your computer and use it in GitHub Desktop.
Save krishnachaitanya7/bc42b4e799dfeff3ec92 to your computer and use it in GitHub Desktop.
I use vpnbook for all my vpn requirements. But they change the password repeatedly. Going to their website note down the password and put them back in VPN config is a robotic work. So i just automated it with python. This script automates the work, By browsing the website extracting the password and saving it to the required config files
'''
Tested in ubuntu 14.04 LTS
Usage: If you dont want the proxy you can comment out the lines 18,19,20
line_writer first argument is the file path which you need to put, then script will update password in that file
i would love to hear from you, hope this script helps you- Email:chaitanyaradon89@gmail.com
'''
from bs4 import BeautifulSoup
import fileinput
import sys
import urllib2
import os
def line_writer(file,searchExp,replaceExp):
for line in fileinput.input(file, inplace=1):
if searchExp in line:
line = line.replace(searchExp,replaceExp)
sys.stdout.write(line)
proxy = urllib2.ProxyHandler({'http': '172.16.30.20:8080'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
html_doc=urllib2.urlopen('http://www.vpnbook.com/freevpn')
soup = BeautifulSoup(html_doc, 'html.parser')
mystring = (soup.get_text())
for item in mystring.split("\n"):
if "Password" in item:
pass_string= item.strip()
final_string = "password="+pass_string[10:]
print "final string is"+final_string
with open ("/etc/NetworkManager/system-connections/VPN connection 1", "r") as myfile:
data=myfile.read()
for item in data.split("\n"):
if "password" in item:
previous_pass_string= item.strip()
print "previou string is "+previous_pass_string
line_writer("/etc/NetworkManager/system-connections/VPN connection 1",previous_pass_string,final_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment