Find out which Interface an IP address is attached to
Hello,
I would like to know if there is a command or something that means something like: Code:
command 192.168.0.1 Code:
#get line number of ifconfig ipaddress is found on Cheers |
Quote:
|
i'm sorry but could you expand a little?
|
does anybody else have more info please??
Quote:
|
O.o was just saying that you should pass an argument to the script instead of writing the IP inside....
I think the output of ifconfig will be pretty consistent across distros. Assuming the ethX is always on the preceding line, you could do: ifconfig | grep -B1 $1 | grep eth this gives you just the line containing "eth" (If for any reason it might show up 2-3 lines back, then just use a higher number in -B) Then you can just use awk to strip off the first field. |
I would suggest just writing a more verbose script. Passing an argument instead of the ip is a great way to start.
|
sorry yes must have confused people a bit, $1 will read in the arguments off a command thats executed and because i used command 192...... you guy's think i'm trying to write a script. The "command [args] 192..." was asking if there is already a command that you can use that will do the job for me (probably should have said "command [parameters] ipaddress}"), if not then i was going to use my own script as shown.
Thanks and judging by replies i'm guessing there's not something that can do this already unless i've confussed people so much know you may understand what i'm trying to say and do know of something?? Sorry ps - thanks pixellany, i was going to say in all the different distro's i've used so far, i've not noticed the output of ifconfig to be to different, also the idea is to allow for any type of interface so not necessarily eth, could be anything. As long as ifconfig doesn't change, my little script will be able to pick up on the interface regardless of what it is. |
All times are GMT -5. The time now is 05:00 PM. |