From 47b0c473626503c69a26189e2292065c38fa1bb9 Mon Sep 17 00:00:00 2001 From: oooldking Date: Fri, 29 Jun 2018 12:52:30 +0800 Subject: [PATCH] 1.add hyper detection. 2.change ip_info api to ipip database. --- ipip.py | 14 ++++++++++++ superbench.sh | 55 +++++++++++++++++++++++++++++++++++++++++------ superbench_git.sh | 46 +++++++++++++++++++++++++++++---------- 3 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 ipip.py diff --git a/ipip.py b/ipip.py new file mode 100644 index 0000000..323c1ef --- /dev/null +++ b/ipip.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +import urllib2 +import json +import sys +reload(sys) +sys.setdefaultencoding('utf-8') + +f = open("ip_json.json",'r') +ijson = json.load(f) +jjson = ijson['location'] + +print jjson[sys.argv[1].encode('utf-8')] \ No newline at end of file diff --git a/superbench.sh b/superbench.sh index 4eac733..0601172 100644 --- a/superbench.sh +++ b/superbench.sh @@ -16,7 +16,7 @@ YELLOW='\033[0;33m' SKYBLUE='\033[0;36m' PLAIN='\033[0m' -about () { +about() { echo "" echo " ========================================================= " echo " \ Superbench.sh Script / " @@ -31,7 +31,7 @@ about () { echo "" } -cancel () { +cancel() { echo "" next; echo " Abort ..." @@ -157,6 +157,13 @@ benchinit() { fi chmod a+rx ip_info.py + # install ipip.py + if [ ! -e 'ipip.py' ]; then + echo " Installing ipip.py ..." + wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ipip.py > /dev/null 2>&1 + fi + chmod a+rx ipip.py + # install fast.com-cli if [ ! -e 'fast_com.py' ]; then echo " Installing Fast.com-cli ..." @@ -360,12 +367,37 @@ ip_info3(){ rm -rf ip_info.py } +ip_info4(){ + echo $(curl -4 -s https://api.ip.la/en?json) > ip_json.json + country=$(python ipip.py country_name) + city=$(python ipip.py city) + isp=$(python ip_info.py isp) + as_tmp=$(python ip_info.py as) + asn=$(echo $as_tmp | awk -F ' ' '{print $1}') + org=$(python ip_info.py org) + countryCode=$(python ipip.py country_code) + region=$(python ipip.py province) + + echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log + echo -e " Organization : ${GREEN}$org${PLAIN}" | tee -a $log + echo -e " Location : ${SKYBLUE}$city, ${GREEN}$country / $countryCode${PLAIN}" | tee -a $log + echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log + + rm -rf ip_info.py + rm -rf ipip.py + rm -rf ip_json.json +} + virt_check(){ if hash ifconfig 2>/dev/null; then eth=$(ifconfig) fi virtualx=$(dmesg) 2>/dev/null + + sys_manu=$(dmidecode -s system-manufacturer) 2>/dev/null + sys_product=$(dmidecode -s system-product-name) 2>/dev/null + sys_ver=$(dmidecode -s system-version) 2>/dev/null if grep docker /proc/1/cgroup -qa; then virtual="Docker" @@ -385,6 +417,14 @@ virt_check(){ virtual="VirtualBox" elif [[ -e /proc/xen ]]; then virtual="Xen" + elif [[ "$sys_manu" == *"Microsoft Corporation"* ]]; then + if [[ "$sys_product" == *"Virtual Machine"* ]]; then + if [[ "$sys_ver" == *"7.0"* || "$sys_ver" == *"Hyper-V" ]]; then + virtual="Hyper-V" + else + virtual="Microsoft Virtual Machine" + fi + fi else virtual="Dedicated" fi @@ -570,7 +610,9 @@ cleanup() { rm -f test_file_*; rm -f speedtest.py; rm -f fast_com*; - rm -f ip_info.py + rm -f ip_info.py; + rm -f ipip.py; + rm -f ip_json.json } bench_all(){ @@ -583,7 +625,7 @@ bench_all(){ next; get_system_info; print_system_info; - ip_info3; + ip_info4; next; print_io; next; @@ -592,6 +634,7 @@ bench_all(){ print_end_time; next; cleanup; + sharetest ubuntu; } fast_bench(){ @@ -604,7 +647,7 @@ fast_bench(){ next; get_system_info; print_system_info; - ip_info3; + ip_info4; next; print_io fast; next; @@ -631,7 +674,7 @@ case $1 in 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' ) about;benchinit;next;print_speedtest;next;cleanup;; 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' ) - about;benchinit;next;ip_info3;next;cleanup;; + about;benchinit;next;ip_info4;next;cleanup;; 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench' ) bench_all;; 'about'|'-about'|'--about' ) diff --git a/superbench_git.sh b/superbench_git.sh index a00dc5c..69dd132 100644 --- a/superbench_git.sh +++ b/superbench_git.sh @@ -15,7 +15,7 @@ YELLOW='\033[0;33m' SKYBLUE='\033[0;36m' PLAIN='\033[0m' -about () { +about() { echo "" echo " ========================================================= " echo " \ Superbench.sh Script / " @@ -30,7 +30,7 @@ about () { echo "" } -cancel () { +cancel() { echo "" next; echo " Abort ..." @@ -107,6 +107,12 @@ benchinit() { fi chmod a+rx ip_info.py + if [ ! -e 'ipip.py' ]; then + echo " Installing ipip.py ..." + wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ipip.py > /dev/null 2>&1 + fi + chmod a+rx ipip.py + if [ ! -e 'fast_com.py' ]; then echo " Installing Fast.com-cli ..." wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com.py > /dev/null 2>&1 @@ -255,15 +261,16 @@ install_smart() { fi } -ip_info3(){ - country=$(python ip_info.py country) - city=$(python ip_info.py city) +ip_info4(){ + echo $(curl -4 -s https://api.ip.la/en?json) > ip_json.json + country=$(python ipip.py country_name) + city=$(python ipip.py city) isp=$(python ip_info.py isp) as_tmp=$(python ip_info.py as) asn=$(echo $as_tmp | awk -F ' ' '{print $1}') org=$(python ip_info.py org) - countryCode=$(python ip_info.py countryCode) - region=$(python ip_info.py regionName) + countryCode=$(python ipip.py country_code) + region=$(python ipip.py province) echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log echo -e " Organization : ${GREEN}$org${PLAIN}" | tee -a $log @@ -271,6 +278,8 @@ ip_info3(){ echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log rm -rf ip_info.py + rm -rf ipip.py + rm -rf ip_json.json } virt_check(){ @@ -279,6 +288,10 @@ virt_check(){ fi virtualx=$(dmesg) 2>/dev/null + + sys_manu=$(dmidecode -s system-manufacturer) 2>/dev/null + sys_product=$(dmidecode -s system-product-name) 2>/dev/null + sys_ver=$(dmidecode -s system-version) 2>/dev/null if grep docker /proc/1/cgroup -qa; then virtual="Docker" @@ -298,6 +311,14 @@ virt_check(){ virtual="VirtualBox" elif [[ -e /proc/xen ]]; then virtual="Xen" + elif [[ "$sys_manu" == *"Microsoft Corporation"* ]]; then + if [[ "$sys_product" == *"Virtual Machine"* ]]; then + if [[ "$sys_ver" == *"7.0"* || "$sys_ver" == *"Hyper-V" ]]; then + virtual="Hyper-V" + else + virtual="Microsoft Virtual Machine" + fi + fi else virtual="Dedicated" fi @@ -458,7 +479,9 @@ cleanup() { rm -f test_file_*; rm -f speedtest.py; rm -f fast_com*; - rm -f ip_info.py + rm -f ip_info.py; + rm -f ipip.py; + rm -f ip_json.json } bench_all(){ @@ -471,7 +494,7 @@ bench_all(){ next; get_system_info; print_system_info; - ip_info3; + ip_info4; next; print_io; next; @@ -480,6 +503,7 @@ bench_all(){ print_end_time; next; cleanup; + sharetest ubuntu; } fast_bench(){ @@ -492,7 +516,7 @@ fast_bench(){ next; get_system_info; print_system_info; - ip_info3; + ip_info4; next; print_io fast; next; @@ -516,7 +540,7 @@ case $1 in 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' ) about;benchinit;next;print_speedtest;next;cleanup;; 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' ) - about;benchinit;next;ip_info3;next;cleanup;; + about;benchinit;next;ip_info4;next;cleanup;; 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench' ) bench_all;; 'about'|'-about'|'--about' )