Python 使用标准输出作为openvpn身份验证用户通行证的输入
我正在编写一个bash脚本来自动连接到VPNBook的免费openvpn服务。我通过调用一个python脚本来收集用户名和密码,该脚本目前只将它们打印到STDOUT 收集用户名和密码的python脚本是:Python 使用标准输出作为openvpn身份验证用户通行证的输入,python,linux,bash,scripting,openvpn,Python,Linux,Bash,Scripting,Openvpn,我正在编写一个bash脚本来自动连接到VPNBook的免费openvpn服务。我通过调用一个python脚本来收集用户名和密码,该脚本目前只将它们打印到STDOUT 收集用户名和密码的python脚本是: #!/bin/python # title: vpnbook-user-pass© # description: Gather vpnbooks username - pass
#!/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脚本的标准输出是:
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:
如何让脚本输入与python脚本一起收集的用户名和密码
我不介意这是bash还是python脚本所有选项都是打开的,但必须是bash或python。看看--auth user pass
选项()
可能最简单的方法是从python脚本中删除带有“用户名和密码组合是:”的行,然后从bash
中启动openvpn
,这样做(对我适用):
在bash中使用:
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( ./fvpn3.py )
openvpn--config-vpnbook-euro1-tcp443.ovpn--auth user pass看一下您的第一个选项似乎是最好的,但它给出了错误2015年10月9日星期五15:07:22发送控制[vpnbook.com]:“PUSH_请求”(状态=1)2015年10月9日星期五15:07:23 auth:收到控制消息:auth_失败2015年10月9日15:07:23 SIGTERM[soft,auth failure]已接收,进程正在退出
您是否删除了打印('用户名和密码组合为:')
行(即python输出的格式是否正确)?添加--动词3
可能会显示所使用的凭据(根据需要,它应该)是的,我删除了该行,动词3产生了相同的输出。@vip谢谢,我今天将处理这个问题,并让您知道我的进展情况。。Thankyou@jamiejackherer你成功了吗?
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( echo -e "${userName}\n${password}" )
#!/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)
openvpn --config vpnbook-euro1-tcp443.ovpn --auth-user-pass <( ./fvpn3.py )