Skip to content

Commit f075baf

Browse files
authored
Add Basic Network Info and VM Type (#56)
* 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.
1 parent 7aa3b79 commit f075baf

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

yabs.sh

100755100644
Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Yet Another Bench Script by Mason Rowe
4-
# Initial Oct 2019; Last update Dec 2022
4+
# Initial Oct 2019; Last update Jan 2023
55

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

1717
echo -e '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #'
1818
echo -e '# Yet-Another-Bench-Script #'
@@ -242,6 +242,65 @@ DISTRO=$(grep 'PRETTY_NAME' /etc/os-release | cut -d '"' -f 2 )
242242
echo -e "Distro : $DISTRO"
243243
KERNEL=$(uname -r)
244244
echo -e "Kernel : $KERNEL"
245+
VIRT=$(systemd-detect-virt)
246+
VIRT=${VIRT^^} || VIRT="UNKNOWN"
247+
echo -e "VM Type : $VIRT"
248+
249+
# Function to get information from IP Address using ip-api.com free API
250+
function ip_info() {
251+
local net_type="$(wget -qO- http://ip6.me/api/ | cut -d, -f1)"
252+
local net_ip="$(wget -qO- http://ip6.me/api/ | cut -d, -f2)"
253+
254+
local response=$(wget -qO- http://ip-api.com/json/$net_ip)
255+
256+
local country=$(echo "$response" | grep -Po '"country": *\K"[^"]*"')
257+
local country=${country//\"}
258+
259+
local region=$(echo "$response" | grep -Po '"regionName": *\K"[^"]*"')
260+
local region=${region//\"}
261+
262+
local region_code=$(echo "$response" | grep -Po '"region": *\K"[^"]*"')
263+
local region_code=${region_code//\"}
264+
265+
local city=$(echo "$response" | grep -Po '"city": *\K"[^"]*"')
266+
local city=${city//\"}
267+
268+
local isp=$(echo "$response" | grep -Po '"isp": *\K"[^"]*"')
269+
local isp=${isp//\"}
270+
271+
local org=$(echo "$response" | grep -Po '"org": *\K"[^"]*"')
272+
local org=${org//\"}
273+
274+
local as=$(echo "$response" | grep -Po '"as": *\K"[^"]*"')
275+
local as=${as//\"}
276+
277+
278+
if [[ -n "$net_type" ]]; then
279+
echo "Protocol : $net_type"
280+
fi
281+
if [[ -z "$net_type" ]]; then
282+
echo "Protocol : Unknown"
283+
fi
284+
if [[ -n "$isp" && -n "$as" ]]; then
285+
echo "ISP : $isp"
286+
echo "ASN : $as"
287+
fi
288+
if [[ -n "$org" ]]; then
289+
echo "Host : $org"
290+
fi
291+
if [[ -n "$city" && -n "$region" ]]; then
292+
echo "Location : $city, $region ($region_code)"
293+
fi
294+
if [[ -n "$country" ]]; then
295+
echo "Country : $country"
296+
fi
297+
}
298+
299+
echo -e
300+
echo -e "Basic Network Information:"
301+
echo -e "---------------------------------"
302+
ip_info
303+
245304
246305
if [ ! -z $JSON ]; then
247306
UPTIME_S=$(awk '{print $1}' /proc/uptime)

0 commit comments

Comments
 (0)