1

how to find the device name as ( e1000g2 , e1000g3 , etc ) according to his IP address on Solaris machine

for example

   ifconfig -a | grep 10.106.134.133

       inet 10.106.134.133 netmask ffffff00 broadcast 10.106.134.255

ifconfig with grep command view only the line with the IP address , and the device name appears before the IP address

so my target is to match the device name according to the IP address on Solaris machine , and then insert the device name in to parameter ( ksh )

please advice?

full example: from ifconfig -a ( I get the IP and device name , what I need is to find the device name according to IP address , and insert the device name in to parameter )

 e1000g2: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500            inet 10.106.134.133 netmask ffffff00 broadcast 10.106.134.255
yael
  • 2,433
  • 5
  • 31
  • 43

1 Answers1

1

This feels like a horrible hack but for now

#!/bin/ksh
ipaddr=$1
ifconfig -a | nawk '/'"$ipaddr"'/ { printf "%s",prev;print };{prev=$0}' | awk '{print $1,$8}'

and

usage scriptname ip.add.re.ss
user9517
  • 115,471
  • 20
  • 215
  • 297