Find the answer to your Linux question:
Results 1 to 2 of 2
Hi I am trying to write a script that would look at the result of arp -a and get the MAC address of an ipaddress. Here is what I have. ...
  1. #1
    mss
    mss is offline
    Just Joined! mss's Avatar
    Join Date
    Jan 2006
    Posts
    45

    bash scripting

    Hi I am trying to write a script that would look at the result of arp -a and get the MAC address of an ipaddress.
    Here is what I have.

    arp -a | awk '192.168.0.$LASTDIGIT {print $4}'

    I get an error message saying

    awk: 1: unexpected character '.'

    Any ideas,
    thanks

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Try:
    Code:
    arp -a | awk '/192.168.0./{ print $4 }'
    That'll print MAC address for everything arp displays in the /24 network.

    What is it you're trying to do with $LASTDIGIT? Expand a variable you've assigned a value to in the shell? If so, then use:
    Code:
    arp -a | awk '/192.168.0.'"$LASTDIGIT"'/{ print $4 }'
    (make sure you copy that exactly.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •