Skip to content

Commit 2b16730

Browse files
committed
improved myip and added myip-global
Signed-off-by: pasquale95 <pasqualeconvertini95@gmail.com>
1 parent b3e2909 commit 2b16730

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.aliases

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ fi
3737

3838
# open current dir in Finder
3939
alias here='open .'
40-
# get machine IP
41-
alias myip='ipconfig getifaddr en0'
4240
# list all TCP ports
4341
alias ports='lsof -iTCP -sTCP:LISTEN -n -P'
4442
# stop all containers

.functions

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,30 @@ size() {
190190

191191
echo "Size:"
192192
du -sh "$1" 2>/dev/null
193+
}
194+
195+
# Return the machine public IP
196+
myip() {
197+
if command -v ip >/dev/null 2>&1; then
198+
# Linux
199+
ip route get 1 | awk '{print $7}'
200+
elif command -v ifconfig >/dev/null 2>&1; then
201+
# macOS and other Unix systems
202+
ifconfig | grep -E 'inet (192|10|172)' | head -1 | awk '{print $2}'
203+
else
204+
# Fallback for systems without ip/ifconfig
205+
echo "Error: Neither 'ip' nor 'ifconfig' command found"
206+
return 1
207+
fi
208+
}
209+
210+
myip-global() {
211+
# Try multiple methods to get public IP
212+
if command -v curl >/dev/null 2>&1; then
213+
curl -s https://api.ipify.org
214+
else
215+
# Fallback to local IP if no external tools available
216+
echo "Error: please install 'curl'"
217+
return 1
218+
fi
193219
}

brew.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ brew install --quiet tree
3636
brew install --quiet nvim
3737
brew install --quiet bash-completion
3838
brew install --quiet ffmpeg
39+
brew install --quiet nmap
40+
brew install --quiet curl
3941

4042
# Clean brew
4143
brew cleanup

0 commit comments

Comments
 (0)