【问题标题】:Use STDOUT as input for openvpn auth-user-pass使用 STDOUT 作为 openvpn auth-user-pass 的输入
【发布时间】: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。

【问题讨论】:

标签: python linux bash scripting openvpn


【解决方案1】:

查看--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 之后将此文件作为参数传递。

this question

编辑>

确认这是有效的(对我而言):

#!/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] 建于 2014 年 12 月 1 日
库版本:OpenSSL 1.0.1k 2015 年 1 月 8 日,LZO 2.08
最初由 James Yonan 开发
版权所有 (C) 2002-2010 OpenVPN Technologies, Inc.
编译时间定义: enable_crypto=yes enable_debug=yes enable_def_auth=是 enable_dependency_tracking=否 enable_dlopen=未知 enable_dlopen_self=未知 enable_dlopen_self_static=未知 enable_fast_install=是 enable_fragment=是 enable_http_proxy=是 enable_iproute2=是 enable_libtool_lock=是 enable_lzo=是 enable_lzo_stub=否 enable_maintainer_mode=no enable_management=yes enable_multi=yes enable_multihome=是 enable_pam_dlopen=否 enable_password_save=是 enable_pedantic=否 enable_pf=是 enable_pkcs11=是 enable_plugin_auth_pam=是 enable_plugin_down_root=是 enable_plugins=是 enable_port_share=是 enable_selinux=否 enable_server=yes enable_shared=yes enable_shared_with_static_runtimes=否 enable_small=否 enable_socks=是 enable_ssl=是 enable_static=是 enable_strict=no enable_strict_options=否 enable_systemd=是 enable_win32_dll=是 enable_x509_alt_username=是 with_crypto_library=openssl with_gnu_ld=是 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=否
git 修订:refs/heads/jessie/b35ad09bfc4a26e7

(请注意enable_password_save=yes

bash --version的输出:

GNU bash,版本 4.3.30(1)-release (x86_64-pc-linux-gnu)
版权 (C) 2013 Free Software Foundation, Inc.
许可 GPLv3+:GNU GPL 版本 3 或更高版本http://gnu.org/licenses/gpl.html

祝你好运!

【讨论】:

  • 您的第一个选项似乎是最好的,但它给出了错误Fri Oct 9 15:07:22 2015 SENT CONTROL [vpnbook.com]: 'PUSH_REQUEST' (status=1) Fri Oct 9 15:07:23 2015 AUTH: Received control message: AUTH_FAILED Fri Oct 9 15:07:23 2015 SIGTERM[soft,auth-failure] received, process exiting
  • 您是否删除了print('The username and password combinantion is:') 行(即python 输出的格式是否正确)?也许添加--verb 3 可以显示使用的凭据(根据errlevel.h 应该)
  • 是的,我删除了该行,--verb 3 产生了相同的输出。
  • @vip 谢谢我今天会处理这个问题,让你知道我是如何重新开始的......谢谢
  • @jamiejackherer 你成功了吗?
猜你喜欢
  • 2022-01-13
  • 1970-01-01
  • 2019-04-06
  • 1970-01-01
  • 2015-06-11
  • 2023-04-04
  • 2021-11-28
  • 2020-09-05
  • 2016-07-08
相关资源
最近更新 更多