aboutsummaryrefslogtreecommitdiff
path: root/functions/test-net.fish
diff options
context:
space:
mode:
authorDeposite Pirate2025-01-12 14:40:33 +0100
committerDeposite Pirate2025-01-12 14:40:33 +0100
commite7764f9b08072cfb67c2d3ecf075df9a80aee6fd (patch)
tree628d5f66e1d62f1d710bcbe472aa68b5e19522f8 /functions/test-net.fish
parent62d7fa8cfa2e6de053d7c1238bd8fdcdf0cc8a7d (diff)
Import config.
Diffstat (limited to 'functions/test-net.fish')
-rw-r--r--functions/test-net.fish58
1 files changed, 58 insertions, 0 deletions
diff --git a/functions/test-net.fish b/functions/test-net.fish
new file mode 100644
index 0000000..93b60aa
--- /dev/null
+++ b/functions/test-net.fish
@@ -0,0 +1,58 @@
+function test-net --description 'Test network connectivity'
+
+if not command -q 'ip'
+ echo "Can't find ip."
+ return 1
+end
+
+if not command -q 'ping'
+ echo "Can't find ping."
+ return 1
+end
+
+if not command -q 'curl'
+ echo "Can't find curl."
+ return 1
+end
+
+set -l extipurl 'https://ifconfig.io'
+
+function print_header -a headertext
+ echo
+ set_color blue
+ echo $headertext
+ set_color normal
+ echo
+end
+
+function print_ip -a label -a ip
+ echo -n $label
+ set_color yellow
+ echo $ip
+ set_color normal
+end
+
+function ping_host -a host
+ echo
+ set_color green
+ ping -q -O -c 1 $host
+ set_color normal
+end
+
+print_header "Testing local connectivity"
+
+set -l gateway "$(ip -c=never -o route show | awk '/default via/ {print $3}')"
+
+print_ip 'Gateway: ' "$gateway"
+ping_host "$gateway"
+
+print_header "Testing internet connectivity"
+
+print_ip 'External IPv4 address: ' "$(curl -s -4 $extipurl)"
+print_ip 'External IPv6 address: ' "$(curl -s -6 $extipurl)"
+
+ping_host 8.8.8.8
+
+echo
+
+end