1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2025-04-18 08:57:40 -05:00
random/getip.sh
2023-08-02 17:10:04 -05:00

19 lines
606 B
Bash

#!/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)"