Python 输出错误
Python Output Error
我正在使用 python 制作一个简单的脚本来检查 IP 是否在 vpn 上或不使用主机名,但是我正在使用 vpn 进行测试并且我在其中使用了我的真实 IP结果读取 "vpn not in use" 即使它是并且输出(“来自 curl 命令)读取如此。
#!/usr/bin/env python
import os
import subprocess
from subprocess import Popen,PIPE
import socket
import time
import optparse
parser = optparse.OptionParser()
parser.add_option("-t", "--hst", action="store", dest="host", help="Target host to check if is using VPN", default=False)
options, args = parser.parse_args()
host = socket.gethostbyname(options.host)
def hostname_check(hst):
check = subprocess.Popen(['curl ipinfo.io/'+hst], shell=True)
if('No Hostname' in str(check)):
print("Host: %s - Virtual Private Network in use") % host
elif('No Hostname' not in str(check)):
print("Host: %s - Virtual Private Network NOT in use") % host
hostname_check(options.host)
要执行的命令:./vpnchecker.py --hst 162.224.81.174
输出:
Host: 162.244.81.174 - Virtual Private Network NOT in use
user@LAPTOP:~$ {
"ip": "162.244.81.174",
"hostname": "No Hostname",
"city": "",
"region": "",
"country": "RO",
"loc": "46.0000,25.0000",
"org": "AS19624 Data Room, Inc"
}
它应该是:主机:162.244.81.174 - 正在使用虚拟专用网络,我不希望 curl 命令的输出显示在屏幕上。
我使用了不同的请求方法,因此我没有使用 curl 来提取网络数据,而是从请求库中获取了相同的数据。这是任何有兴趣的人的代码:
#!/usr/bin/env python
import os
import subprocess
from subprocess import Popen,PIPE
import socket
import time
import requests
import optparse
parser = optparse.OptionParser()
parser.add_option("-t", "--hst", action="store", dest="host", help="Target host to check if is using VPN", default=False)
from requests import *
options, args = parser.parse_args()
host = socket.gethostbyname(options.host)
def hostname_check(hst):
check = requests.get('http://ipinfo.io/'+hst).text
if('No Hostname' in check):
print("Host: %s - Virtual Private Network in use") % host
elif('No Hostname' not in check):
print("Host: %s - Virtual Private Network NOT in use") % host
hostname_check(options.host)
我正在使用 python 制作一个简单的脚本来检查 IP 是否在 vpn 上或不使用主机名,但是我正在使用 vpn 进行测试并且我在其中使用了我的真实 IP结果读取 "vpn not in use" 即使它是并且输出(“来自 curl 命令)读取如此。
#!/usr/bin/env python
import os
import subprocess
from subprocess import Popen,PIPE
import socket
import time
import optparse
parser = optparse.OptionParser()
parser.add_option("-t", "--hst", action="store", dest="host", help="Target host to check if is using VPN", default=False)
options, args = parser.parse_args()
host = socket.gethostbyname(options.host)
def hostname_check(hst):
check = subprocess.Popen(['curl ipinfo.io/'+hst], shell=True)
if('No Hostname' in str(check)):
print("Host: %s - Virtual Private Network in use") % host
elif('No Hostname' not in str(check)):
print("Host: %s - Virtual Private Network NOT in use") % host
hostname_check(options.host)
要执行的命令:./vpnchecker.py --hst 162.224.81.174 输出:
Host: 162.244.81.174 - Virtual Private Network NOT in use
user@LAPTOP:~$ {
"ip": "162.244.81.174",
"hostname": "No Hostname",
"city": "",
"region": "",
"country": "RO",
"loc": "46.0000,25.0000",
"org": "AS19624 Data Room, Inc"
}
它应该是:主机:162.244.81.174 - 正在使用虚拟专用网络,我不希望 curl 命令的输出显示在屏幕上。
我使用了不同的请求方法,因此我没有使用 curl 来提取网络数据,而是从请求库中获取了相同的数据。这是任何有兴趣的人的代码:
#!/usr/bin/env python
import os
import subprocess
from subprocess import Popen,PIPE
import socket
import time
import requests
import optparse
parser = optparse.OptionParser()
parser.add_option("-t", "--hst", action="store", dest="host", help="Target host to check if is using VPN", default=False)
from requests import *
options, args = parser.parse_args()
host = socket.gethostbyname(options.host)
def hostname_check(hst):
check = requests.get('http://ipinfo.io/'+hst).text
if('No Hostname' in check):
print("Host: %s - Virtual Private Network in use") % host
elif('No Hostname' not in check):
print("Host: %s - Virtual Private Network NOT in use") % host
hostname_check(options.host)