【发布时间】:2016-01-06 01:47:51
【问题描述】:
我正在编写一个 bash 脚本来自动连接到 VPNBook 的免费 openvpn 服务。我通过调用当前只是将它们打印到 STDOUT 的 python 脚本来收集用户名和密码。
收集用户名和密码的python脚本是:
#!/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:
如何让我的脚本输入使用 python 脚本收集的用户名和密码?
我不介意这是 bash 还是 python 脚本,所有选项都是打开的,但必须是 bash 或 python。
【问题讨论】:
-
看看
expect
标签: python linux bash scripting openvpn