Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Created September 11, 2013 01:41
Show Gist options
  • Select an option

  • Save tskrynnyk/6518366 to your computer and use it in GitHub Desktop.

Select an option

Save tskrynnyk/6518366 to your computer and use it in GitHub Desktop.
Update password for vpnbook.com in NeworkManager.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, re, fileinput, glob
from BeautifulSoup import BeautifulSoup
import urllib2
page = urllib2.urlopen("http://www.vpnbook.com/")
soup = BeautifulSoup(page)
data = soup.find("li", id="openvpn")
conffiles = glob.glob("/etc/NetworkManager/system-connections/VPNBOOK*")
for tag in data.findAll('strong'):
u = re.findall('Username:\s+(\w+)', str(tag.contents))
if u:
username = u[0]
continue
p = re.findall('Password:\s+(\w+)', str(tag.contents))
if p:
password = p[0]
break
if username and password:
if conffiles:
for line in fileinput.FileInput(conffiles,inplace=1):
if 'password=' in line:
line=line.replace(line,"password=" + password + "\n")
sys.stdout.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment