From 3a2f1761e58736d614ae8f42980a78b5a64a3f84 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 2 Aug 2023 17:10:04 -0500 Subject: [PATCH] new: Added getip.sh --- README.md | 2 +- getip.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 getip.sh diff --git a/README.md b/README.md index 42f75b8..45d157e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Number of scripts](https://img.shields.io/badge/number_of_scripts-38-blue) +![Number of scripts](https://img.shields.io/badge/number_of_scripts-39-blue) # Random Scripts This repository is for random scripts I wrote mostly for personal use. diff --git a/getip.sh b/getip.sh new file mode 100644 index 0000000..0ec6676 --- /dev/null +++ b/getip.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# This is a simple script to get the ip addresses of a machine. + +echo 'ipv4:' +for i in eno1 wlan0; do + addr="$(ip -4 addr show dev $i | grep -oP '(?<=inet\s)\d+(\.\d+){3}')" + [ -z "$addr" ] || echo -e "\t$i: \t\t$addr" +done +echo -e "\texternal: \t$(curl -s ipv4.icanhazip.com)" + +[ "$(cat /sys/module/ipv6/parameters/disable)" == "1" ] && exit + +echo 'ipv6:' +for i in eno1 wlan0; do + addr="$(ip -6 addr show dev $i | grep -oP '(?<=inet6\s)\w+(\:{1,2}\w+){4}(?=.+link)')" + [ -z "$addr" ] || echo -e "\t$i: \t\t$addr" +done +echo -e "\texternal: \t$(curl -s ipv6.icanhazip.com)"