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.
Webinar: 8 Signs You’re Beyond Cron
11am CDT, April 29th
Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.Join us!
- Return of the Mac
- DevOps: Better Than the Sum of Its Parts
- Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites
- Not So Dynamic Updates
- Play for Me, Jarvis
- Users, Permissions and Multitenant Sites
- Non-Linux FOSS: .NET?
- Designing Foils with XFLR5
- diff -u: What's New in Kernel Development