Skip to content

.bashrc_fix_whatsmyip_function - #107

Merged
ChrisTitusTech merged 1 commit into
ChrisTitusTech:mainfrom
jasonritchie06:main
Jul 13, 2026
Merged

.bashrc_fix_whatsmyip_function#107
ChrisTitusTech merged 1 commit into
ChrisTitusTech:mainfrom
jasonritchie06:main

Conversation

@jasonritchie06

Copy link
Copy Markdown
Contributor

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

technicks89 commented May 20, 2026

Copy link
Copy Markdown

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
Contributor 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 :)

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.
@ChrisTitusTech

Copy link
Copy Markdown
Owner

Updated this PR onto the current main branch in commit 77e9010.

The original fix is preserved while resolving the overlap with newer changes:

  • Current main already replaced the hard-coded wlan0 lookup with route-based source-address detection, which supports modern wireless interface names as well as other active interfaces.
  • The PR's remaining newline fix is retained so successful and failed external IP lookups both end cleanly on a new line.

Validation completed:

  • bash -n .bashrc
  • shellcheck .bashrc
  • git diff --check
  • Focused whatsmyip success and failure output checks, including the final newline

@ChrisTitusTech
ChrisTitusTech merged commit f413426 into ChrisTitusTech:main Jul 13, 2026
2 checks passed
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.

3 participants