1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-26 05:08:36 -06:00

new: Added getip.sh

This commit is contained in:
Sayantan Santra 2023-08-02 17:10:04 -05:00
parent 16eb2379cd
commit 3a2f1761e5
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
2 changed files with 20 additions and 1 deletions

View file

@ -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 # Random Scripts
This repository is for random scripts I wrote mostly for personal use. This repository is for random scripts I wrote mostly for personal use.

19
getip.sh Normal file
View file

@ -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)"