Find details of device based on dns name using ip command











up vote
0
down vote

favorite












When I'm retrieving the mac address of a device
I execute following command



$ arp <dnsname> | grep "HWaddress" -A1 | awk '{print $1 "" $3}' |head -2 | tail -1


this will probably print



<dnsname> <mac address> 


As I've seen from the manual of arp is that it is deprecated and alternate I have is to use 'ip' command instead of arp .










share|improve this question
























  • Your question is not clear. Do you want to obtain the mac address using ip command?
    – Helio
    Sep 20 '17 at 19:33










  • Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
    – roaima
    Sep 20 '17 at 20:42










  • @Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
    – Harish Barma
    Sep 21 '17 at 8:23












  • @roaima I will pass the dnsname in the local network and fetch the mac address
    – Harish Barma
    Sep 21 '17 at 8:24















up vote
0
down vote

favorite












When I'm retrieving the mac address of a device
I execute following command



$ arp <dnsname> | grep "HWaddress" -A1 | awk '{print $1 "" $3}' |head -2 | tail -1


this will probably print



<dnsname> <mac address> 


As I've seen from the manual of arp is that it is deprecated and alternate I have is to use 'ip' command instead of arp .










share|improve this question
























  • Your question is not clear. Do you want to obtain the mac address using ip command?
    – Helio
    Sep 20 '17 at 19:33










  • Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
    – roaima
    Sep 20 '17 at 20:42










  • @Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
    – Harish Barma
    Sep 21 '17 at 8:23












  • @roaima I will pass the dnsname in the local network and fetch the mac address
    – Harish Barma
    Sep 21 '17 at 8:24













up vote
0
down vote

favorite









up vote
0
down vote

favorite











When I'm retrieving the mac address of a device
I execute following command



$ arp <dnsname> | grep "HWaddress" -A1 | awk '{print $1 "" $3}' |head -2 | tail -1


this will probably print



<dnsname> <mac address> 


As I've seen from the manual of arp is that it is deprecated and alternate I have is to use 'ip' command instead of arp .










share|improve this question















When I'm retrieving the mac address of a device
I execute following command



$ arp <dnsname> | grep "HWaddress" -A1 | awk '{print $1 "" $3}' |head -2 | tail -1


this will probably print



<dnsname> <mac address> 


As I've seen from the manual of arp is that it is deprecated and alternate I have is to use 'ip' command instead of arp .







linux dns ip arp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 20:41









Rui F Ribeiro

38.3k1475126




38.3k1475126










asked Sep 20 '17 at 15:15









Harish Barma

1032




1032












  • Your question is not clear. Do you want to obtain the mac address using ip command?
    – Helio
    Sep 20 '17 at 19:33










  • Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
    – roaima
    Sep 20 '17 at 20:42










  • @Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
    – Harish Barma
    Sep 21 '17 at 8:23












  • @roaima I will pass the dnsname in the local network and fetch the mac address
    – Harish Barma
    Sep 21 '17 at 8:24


















  • Your question is not clear. Do you want to obtain the mac address using ip command?
    – Helio
    Sep 20 '17 at 19:33










  • Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
    – roaima
    Sep 20 '17 at 20:42










  • @Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
    – Harish Barma
    Sep 21 '17 at 8:23












  • @roaima I will pass the dnsname in the local network and fetch the mac address
    – Harish Barma
    Sep 21 '17 at 8:24
















Your question is not clear. Do you want to obtain the mac address using ip command?
– Helio
Sep 20 '17 at 19:33




Your question is not clear. Do you want to obtain the mac address using ip command?
– Helio
Sep 20 '17 at 19:33












Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
– roaima
Sep 20 '17 at 20:42




Do you want to retrieve the MAC address of the device running this code, or of some arbitrary device on the same LAN?
– roaima
Sep 20 '17 at 20:42












@Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
– Harish Barma
Sep 21 '17 at 8:23






@Helio my input is dnsname and my required output is mac address. by above command I can do it easily but arp is depricated and i was suggested to use 'ip'. so I need to achieve the same result using 'ip'
– Harish Barma
Sep 21 '17 at 8:23














@roaima I will pass the dnsname in the local network and fetch the mac address
– Harish Barma
Sep 21 '17 at 8:24




@roaima I will pass the dnsname in the local network and fetch the mac address
– Harish Barma
Sep 21 '17 at 8:24










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










arp is able to take names as input and print names in output. ip uses addresses only.



If you can deal with addresses, then modifying the output is pretty easy.



$ ip neigh show to 10.0.0.1
10.0.0.1 dev wlan0 lladdr dc:fb:02:xx:xx:xx REACHABLE

$ ip neigh show to 10.0.0.1 | awk '{print $1 " " $5}'
10.0.0.1 dc:fb:02:xx:xx:xx


I just noticed that your title specifically asks about DNS names. If that's the requirement, then you'll want to translate the name in your script.



$ ip neigh show to `getent hosts <dnsname> | awk '{print $1}'` | awk '{print $1 " " $5}'
$ 10.0.0.1 dc:fb:02:xx:xx:xx





share|improve this answer























  • You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
    – roaima
    Sep 21 '17 at 10:11











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f393430%2ffind-details-of-device-based-on-dns-name-using-ip-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










arp is able to take names as input and print names in output. ip uses addresses only.



If you can deal with addresses, then modifying the output is pretty easy.



$ ip neigh show to 10.0.0.1
10.0.0.1 dev wlan0 lladdr dc:fb:02:xx:xx:xx REACHABLE

$ ip neigh show to 10.0.0.1 | awk '{print $1 " " $5}'
10.0.0.1 dc:fb:02:xx:xx:xx


I just noticed that your title specifically asks about DNS names. If that's the requirement, then you'll want to translate the name in your script.



$ ip neigh show to `getent hosts <dnsname> | awk '{print $1}'` | awk '{print $1 " " $5}'
$ 10.0.0.1 dc:fb:02:xx:xx:xx





share|improve this answer























  • You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
    – roaima
    Sep 21 '17 at 10:11















up vote
1
down vote



accepted










arp is able to take names as input and print names in output. ip uses addresses only.



If you can deal with addresses, then modifying the output is pretty easy.



$ ip neigh show to 10.0.0.1
10.0.0.1 dev wlan0 lladdr dc:fb:02:xx:xx:xx REACHABLE

$ ip neigh show to 10.0.0.1 | awk '{print $1 " " $5}'
10.0.0.1 dc:fb:02:xx:xx:xx


I just noticed that your title specifically asks about DNS names. If that's the requirement, then you'll want to translate the name in your script.



$ ip neigh show to `getent hosts <dnsname> | awk '{print $1}'` | awk '{print $1 " " $5}'
$ 10.0.0.1 dc:fb:02:xx:xx:xx





share|improve this answer























  • You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
    – roaima
    Sep 21 '17 at 10:11













up vote
1
down vote



accepted







up vote
1
down vote



accepted






arp is able to take names as input and print names in output. ip uses addresses only.



If you can deal with addresses, then modifying the output is pretty easy.



$ ip neigh show to 10.0.0.1
10.0.0.1 dev wlan0 lladdr dc:fb:02:xx:xx:xx REACHABLE

$ ip neigh show to 10.0.0.1 | awk '{print $1 " " $5}'
10.0.0.1 dc:fb:02:xx:xx:xx


I just noticed that your title specifically asks about DNS names. If that's the requirement, then you'll want to translate the name in your script.



$ ip neigh show to `getent hosts <dnsname> | awk '{print $1}'` | awk '{print $1 " " $5}'
$ 10.0.0.1 dc:fb:02:xx:xx:xx





share|improve this answer














arp is able to take names as input and print names in output. ip uses addresses only.



If you can deal with addresses, then modifying the output is pretty easy.



$ ip neigh show to 10.0.0.1
10.0.0.1 dev wlan0 lladdr dc:fb:02:xx:xx:xx REACHABLE

$ ip neigh show to 10.0.0.1 | awk '{print $1 " " $5}'
10.0.0.1 dc:fb:02:xx:xx:xx


I just noticed that your title specifically asks about DNS names. If that's the requirement, then you'll want to translate the name in your script.



$ ip neigh show to `getent hosts <dnsname> | awk '{print $1}'` | awk '{print $1 " " $5}'
$ 10.0.0.1 dc:fb:02:xx:xx:xx






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 20 '17 at 22:11

























answered Sep 20 '17 at 21:59









BowlOfRed

2,425715




2,425715












  • You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
    – roaima
    Sep 21 '17 at 10:11


















  • You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
    – roaima
    Sep 21 '17 at 10:11
















You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
– roaima
Sep 21 '17 at 10:11




You'll be better using $( ... ) instead of backticks, i.e. ip neigh show to $(getent hosts <dnsname> | awk '{print $1}') | awk '{print $1 " " $5}'
– roaima
Sep 21 '17 at 10:11


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f393430%2ffind-details-of-device-based-on-dns-name-using-ip-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Accessing regular linux commands in Huawei's Dopra Linux