Skip to content

.bashrc_fix_whatsmyip_function#107

Open
jasonritchie06 wants to merge 2 commits into
ChrisTitusTech:mainfrom
jasonritchie06:main
Open

.bashrc_fix_whatsmyip_function#107
jasonritchie06 wants to merge 2 commits into
ChrisTitusTech:mainfrom
jasonritchie06:main

Conversation

@jasonritchie06
Copy link
Copy Markdown

Add support to correctly identify actual wlan interface name for whatsmyip function. Where wlan0 was hard coded we now try to identify actual device. On newer Ubuntu installs, the device is usually begins with wlp. If the iw command is not available, we fail back to hard coded wlan0. Also added a carriage return after the command to begin a new line.

Add support to correctly identify actual wlan interface name for whatsmyip function. Where wlan0 was hard coded we now try to identify actual device. On newer Ubuntu installs, the device is usually begins with wlp. If the iw command is not available, we fail back to hard coded wlan0. Also added a carriage return after the command to begin a new line.
@technicks89
Copy link
Copy Markdown

technicks89 commented May 20, 2026

I was looking into updating this as well using nmcli, Maybe we combine iw and nmcli as options.

function whatsmyip () {
# Internal IP Lookup.
if command -v iw &> /dev/null; then
# try to find correct wlan interface on system. Newer Ubuntu uses wlp
DEV=$(iw dev | awk '/Interface/ {interf=$2} END {print interf}')
elif command -v nmcli &> /dev/null; then
DEV="$(nmcli device | awk 'NR==2{print $2}')"
else
#fail back to trying wlan0
DEV=wlan0
fi

if command -v ip &> /dev/null; then
    echo -n "Internal IP: "
    ip addr show $DEV | grep "inet " | awk '{print $2}' | cut -d/ -f1
else
    echo -n "Internal IP: "
    ifconfig $DEV | grep "inet " | awk '{print $2}'
fi

# External IP Lookup
echo -n "External IP: "
curl -s ifconfig.me
echo -e

}

@jasonritchie06
Copy link
Copy Markdown
Author

It's been over a year and I never heard back from Chris that this pull was merged so I don't think anyone cares at this point.

@technicks89
Copy link
Copy Markdown

@ChrisTitusTech Please review, this would be a useful change for many setups that don't have wlan0 as their default connection

@technicks89
Copy link
Copy Markdown

It's been over a year and I never heard back from Chris that this pull was merged so I don't think anyone cares at this point.

Still worth trying :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants