Created
September 11, 2013 01:41
-
-
Save tskrynnyk/6518366 to your computer and use it in GitHub Desktop.
Update password for vpnbook.com in NeworkManager.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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