Tech Tip: Getting Your MAC and IP Address In a Script
Ever wanted to get the MAC or IP address of your computer in a Linux shell script? The following two commands should work on most flavours of Linux/Unix.
To get your IP address:
/sbin/ifconfig \ | grep '\<inet\>' \ | sed -n '1p' \ | tr -s ' ' \ | cut -d ' ' -f3 \ | cut -d ':' -f2
To get your MAC address (Hardware address):
/sbin/ifconfig \ | grep 'eth0' \ | tr -s ' ' \ | cut -d ' ' -f5
Note that this retrieves the address of the eth0 interface by default.
- Readers' Choice Awards 2013
- Mars Needs Women
- RSS Feeds
- Sublime Text: One Editor to Rule Them All?
- December 2013 Issue of Linux Journal: Readers' Choice
- Raspberry Pi: the Perfect Home Server
- IBM Will Minimize Impact of Future Disasters
- Linux Systems Administrator
- Tech Tip: Really Simple HTTP Server with Python
- Senior Perl Developer
- So girls had it better ?
2 hours 53 min ago
- Reply to comment | Linux Journal
3 hours 13 min ago
- why is GNOME 3 in the fifth position at 14.1 %?
8 hours 46 min ago
- Sublime Is Brilliant!
13 hours 48 min ago
14 hours 8 min ago
- Rapid[Disk,Cache] better than native ram caching?
14 hours 33 min ago
- Nothing is perfect
14 hours 46 min ago
- Mixtapes Community
20 hours 25 min ago
- KDE is one true DE
20 hours 59 min ago
- Command Line Shells (Bash, Zsh, etc.) are 2nd place
21 hours 28 min ago