我正在编写一个bash脚本来自动连接到VPNBook的免费openvpn服务.我通过调用python脚本来收集用户名和密码,该脚本当前只是将它们打印到STDOUT.
#!/bin/python
# title: vpnbook-user-pass©
# description: Gather vpnbooks username - password combinantion
# author: jack herer
# date: Tuesday 06 October 2015 @ 10:29:14 am
# version: v1.0
# usage: python vpnbook-user-pass
# notes: ~
# bash version: 4.3.30(1)-release
#========================================
# copyright © | jack herer | 2015
#========================================
from bs4 import BeautifulSoup
import requests
response = requests.get('http://vpnbook.com/freevpn')
soup = BeautifulSoup(response.text, 'html.parser')
pricing = soup.find(id = 'pricing')
first_column = pricing.find('div', {'class': 'one-third'})
for li in first_column.find('ul', {'class': 'disc'}):
if 'username' in str(li).lower():
username = li.find('strong').text
print('The username and password combinantion is:')
print(username)
response = requests.get('http://vpnbook.com/freevpn')
soup = BeautifulSoup(response.text, 'html.parser')
pricing = soup.find(id = 'pricing')
first_column = pricing.find('div', {'class': 'one-third'})
for li in first_column.find('ul', {'class': 'disc'}):
if 'password' in str(li).lower():
password = li.find('strong').text
print(password)
python脚本的STDOUT是:
The username and password combinantion is:
vpnbook
JE5Raphu
到目前为止的bash脚本:
# !/bin/bash -
# title: auto-vpn©
# description: Automatically connect to vpnbook's free vpn service
# author: jack herer
# date: Thursday 08 October 2015 @ 11:49:21 am
# version: v1.0
# usage: ./auto-vpn
# notes: ~
# bash version: 4.3.30(1)-release
#========================================
# copyright © | jack herer | 2015
#========================================
userpass=$(python ~/vpnbook-user-pass)
echo "${userpass} "
cd $HOME/vpnbook/
openvpn --config vpnbook-euro1-tcp443.ovpn
最后一个命令openvpn –config vpnbook-euro1-tcp443.ovpn然后运行并要求我输入如下的用户名和密码:
Thu Oct 8 13:20:28 2015 OpenVPN 2.3.4 i586-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH] [IPv6] built on Dec 1 2014
Thu Oct 8 13:20:28 2015 library versions: OpenSSL 1.0.1k 8 Jan 2015, LZO 2.08
Enter Auth Username:
Enter Auth Password:
我不介意这是一个bash或python脚本,所有选项都是打开的,但必须是bash或python.
解决方法:
看看–auth-user-pass选项(here).
对你来说最简单的方法是从你的python脚本中删除“用户名和密码组合是:”的行,并以这种方式从bash启动openvpn(适用于我):
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( python ~/vpnbook-user-pass )
通常,类似于:
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( echo -e "${userName}\n${password}" )
也应该工作(适合我).
或者,您可以将凭据保存到文件中(确保它不是世界可读的),并在–auth-user-pass之后将此文件作为参数传递.
编辑>
确认这是有效的(对我来说):
#!/usr/bin/python
from bs4 import BeautifulSoup
import requests
response = requests.get('http://vpnbook.com/freevpn')
soup = BeautifulSoup(response.text, 'html.parser')
pricing = soup.find(id = 'pricing')
first_column = pricing.find('div', {'class': 'one-third'})
for li in first_column.find('ul', {'class': 'disc'}):
if 'username' in str(li).lower():
username = li.find('strong').text
if 'password' in str(li).lower():
password = li.find('strong').text
print(username)
print(password)
用于bash:
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( ./fvpn3.py )
openvpn –version的输出:
OpenVPN 2.3.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL]
[PKCS11] [MH] [IPv6] built on Dec 1 2014
library versions: OpenSSL
1.0.1k 8 Jan 2015, LZO 2.08
Originally developed by James Yonan
copyright (C) 2002-2010 OpenVPN Technologies, Inc.
Compile time defines: enable_crypto=yes enable_debug=yes
enable_def_auth=yes enable_dependency_tracking=no
enable_dlopen=unkNown enable_dlopen_self=unkNown
enable_dlopen_self_static=unkNown enable_fast_install=yes
enable_fragment=yes enable_http_proxy=yes enable_iproute2=yes
enable_libtool_lock=yes enable_lzo=yes enable_lzo_stub=no
enable_maintainer_mode=no enable_management=yes enable_multi=yes
enable_multihome=yes enable_pam_dlopen=no enable_password_save=yes
enable_pedantic=no enable_pf=yes enable_pkcs11=yes
enable_plugin_auth_pam=yes enable_plugin_down_root=yes
enable_plugins=yes enable_port_share=yes enable_selinux=no
enable_server=yes enable_shared=yes
enable_shared_with_static_runtimes=no enable_small=no enable_socks=yes
enable_ssl=yes enable_static=yes enable_strict=no
enable_strict_options=no enable_systemd=yes enable_win32_dll=yes
enable_x509_alt_username=yes with_crypto_library=openssl
with_gnu_ld=yes with_ifconfig_path=/sbin/ifconfig
with_iproute_path=/sbin/ip with_mem_check=no
with_plugindir=’${prefix}/lib/openvpn’ with_route_path=/sbin/route
with_sysroot=no
git revision: refs/heads/jessie/b35ad09bfc4a26e7
(请注意enable_password_save =是)
bash的输出–version:
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
copyright
(C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL
version 3 or later 07002
祝好运!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。