Skip to content

Commit

Permalink
Add Basic Network Info and VM Type (#56)
Browse files Browse the repository at this point in the history
* Add Basic Network Info

Added a function to display basic details from IP Address lookup. Use ip-api.com free API for this.

* Add VM Type in Basic Info

Add Virtualization type in basic info.
Inspired from bench.sh

* Suppress Error messages on VM check

* Better way to find virtualization

Most modern Linux systems use systemd as the system and service manager. The systemd package ships with the systemd-detect-virt utility, which we can use to detect a virtualization technology.
  • Loading branch information
su-haris authored Feb 26, 2023
1 parent 7aa3b79 commit f075baf
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions yabs.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Yet Another Bench Script by Mason Rowe
# Initial Oct 2019; Last update Dec 2022
# Initial Oct 2019; Last update Jan 2023

# Disclaimer: This project is a work in progress. Any errors or suggestions should be
# relayed to me via the GitHub project page linked below.
Expand All @@ -12,7 +12,7 @@
# performance via fio. The script is designed to not require any dependencies
# - either compiled or installed - nor admin privileges to run.
#
YABS_VERSION="v2022-12-29"
YABS_VERSION="v2023-02-03"

echo -e '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #'
echo -e '# Yet-Another-Bench-Script #'
Expand Down Expand Up @@ -242,6 +242,65 @@ DISTRO=$(grep 'PRETTY_NAME' /etc/os-release | cut -d '"' -f 2 )
echo -e "Distro : $DISTRO"
KERNEL=$(uname -r)
echo -e "Kernel : $KERNEL"
VIRT=$(systemd-detect-virt)
VIRT=${VIRT^^} || VIRT="UNKNOWN"
echo -e "VM Type : $VIRT"
# Function to get information from IP Address using ip-api.com free API
function ip_info() {
local net_type="$(wget -qO- http://ip6.me/api/ | cut -d, -f1)"
local net_ip="$(wget -qO- http://ip6.me/api/ | cut -d, -f2)"
local response=$(wget -qO- http://ip-api.com/json/$net_ip)
local country=$(echo "$response" | grep -Po '"country": *\K"[^"]*"')
local country=${country//\"}
local region=$(echo "$response" | grep -Po '"regionName": *\K"[^"]*"')
local region=${region//\"}
local region_code=$(echo "$response" | grep -Po '"region": *\K"[^"]*"')
local region_code=${region_code//\"}
local city=$(echo "$response" | grep -Po '"city": *\K"[^"]*"')
local city=${city//\"}
local isp=$(echo "$response" | grep -Po '"isp": *\K"[^"]*"')
local isp=${isp//\"}
local org=$(echo "$response" | grep -Po '"org": *\K"[^"]*"')
local org=${org//\"}
local as=$(echo "$response" | grep -Po '"as": *\K"[^"]*"')
local as=${as//\"}
if [[ -n "$net_type" ]]; then
echo "Protocol : $net_type"
fi
if [[ -z "$net_type" ]]; then
echo "Protocol : Unknown"
fi
if [[ -n "$isp" && -n "$as" ]]; then
echo "ISP : $isp"
echo "ASN : $as"
fi
if [[ -n "$org" ]]; then
echo "Host : $org"
fi
if [[ -n "$city" && -n "$region" ]]; then
echo "Location : $city, $region ($region_code)"
fi
if [[ -n "$country" ]]; then
echo "Country : $country"
fi
}
echo -e
echo -e "Basic Network Information:"
echo -e "---------------------------------"
ip_info
if [ ! -z $JSON ]; then
UPTIME_S=$(awk '{print $1}' /proc/uptime)
Expand Down

0 comments on commit f075baf

Please sign in to comment.