-2

I need help with a shell script to display my current IP Address and MAC Address with a "|" in between them like this:

IP Address:  | MAC Address: 

So can this be done easily in a shell script?

closed as off-topic by Steffen Ullrich, Arminius, Teun Vink, Bacon Brad, Mike Ounsworth Aug 5 '17 at 2:29

  • This question does not appear to be about Information security within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    I'm voting to close this question as off-topic because it is not about information security. It might be more on topic on stackoverflow.com because this site is about coding - but they expect to at least try yourself first and help with specific problems instead of doing all the coding for you as you expect here. – Steffen Ullrich Aug 4 '17 at 20:48
-1

Shell Script:

#!/bin/bash

IF=$(route | grep '^default' | grep -o '[^ ]*$')
IP=$(ip addr show $IF | awk '/inet / {print $2}' | cut -d/ -f 1)
MAC=$(ip link show $IF | awk '/ether/ {print $2}')

echo "IP Address: $IP | MAC Address: $MAC"

Look into grep, awk, and sed to learn more about text processing and doing more tasks like this.

Not the answer you're looking for? Browse other questions tagged or ask your own question.