# Npm function @network-utils/arp-lookup weird Promise output

**URL:** <https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412>\
**Category:** General\
**Created:** [29 February 2020 15:43 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412 "2020-02-29T15:43:34Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [2 March 2020 19:20 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/21 "2020-03-02T19:20:22Z")

</div>

tried that but still giving the same error  
when i bypass that code (the code which writes the second address line) and edit the xml file so the localhost has 2 address entries i am advanding a little more

however second error

"TypeError: Cannot read property 'AC:AC:0B:E9:6A:FF' of undefined"

it seems to try and read the ip address belonging to that mac address(the first one in the xml file)

i think it halts at this line

network[mac].ipaddr = host.address[0].$.addr

this is what is in the xml file (note there is no vendor info, deleting the vendor code will not help either)

```auto
<host><status state="up" reason="arp-response" reason_ttl="0"/>
<address addr="192.168.1.1" addrtype="ipv4"/>
<address addr="AC:AC:0B:E9:6A:FF" addrtype="mac"/>
<hostnames>
<hostname name="RT-AC66U-27E8" type="PTR"/>
</hostnames>
<times srtt="632" rttvar="5000" to="100000"/>
</host>

```

when translated to json still i see no strange things  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d89840c850e7f14379cfef6f77769e01e9b5fbf.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 March 2020 20:13 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/22 "2020-03-02T20:13:26Z")

</div>

If you put a debug node set to show the full msg after the XML node, you should get something like:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/466a3727dbb90f7b47ad910b97abc7f34245811c.png)

If you put one on the output of the file read node, it should look something like:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/7206ed18fc12422f800f4ba8a623eff894e30108.png)

The lack of vendor info doesn't matter.

` host.address[0].$.addr` should return your router's address quite happily on the first line as you show in the debug output. You can prove that by using some `node.warn()` functions in the function node.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 March 2020 20:17 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/23 "2020-03-02T20:17:04Z")

</div>

> [@GravityRZ](#):
>
> TypeError: Cannot read property 'hasOwnProperty' of undefined

No, hang-on, just re-read that error. hasOwnProperty is only used once:

```auto
    // Create the entry if it doesn't exist
    if ( ! network.hasOwnProperty(mac) ) {
        // ID = mac for anything coming from nmap
        network[mac] = { id: mac, 'mac': mac }
        newnetwork[mac] = host
    }

```

That means that the variable `network` doesn't exist which means that it failed to read it.

To fix that, try changing the first line to:

```auto
const network = global.get('network','file') || {}

```

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [2 March 2020 21:05 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/24 "2020-03-02T21:05:51Z")

</div>

such a simple solution, i was totally looking in the wrong direction.

thanks

no i have to use that data in my flow

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [4 March 2020 19:05 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/25 "2020-03-04T19:05:58Z")

</div>

got it working but i have one question.

every device shows up in the global.get  
however when you disable a device(let's say your iphone) and run the flow again the entry for the iphone disappears.  
i thought al the entries which were scanned are supposed to stay in the global.get and only the status(ipstate) should change.

so over time the global.get has all the existing devices but the status depends on whether they are switched on or off.

i currently us an exec node which i feed with an ip address and executes arp -a  
this looks in the arp cache table and also displays the status  
if i get an incomplete message it means the unit is not connected, when it responds with the mac address it means it is on.  
when it can not find the entry it means the device is off and has never been seen before

my synology does not repond with anything (but it is on and available)  
somehow it does not show up in the arp cache that is why i wanted to use nmap as a backup

problem with nmap seems to be(with option sn) that it shows up when on but does not show up when off.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 March 2020 23:24 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/26 "2020-03-04T23:24:18Z")

</div>

> [@GravityRZ](#):
>
> i thought al the entries which were scanned are supposed to stay in the global.get and only the status(ipstate) should change.

That should be what is happening and I think it is happening on mine ... yes, just checked. I started off with about 61 devices discovered and I now have 70.

> [@GravityRZ](#):
>
> my synology does not repond with anything (but it is on and available)  
> somehow it does not show up in the arp cache that is why i wanted to use nmap as a backup

My Synology NAS shows up fine using nmap:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4be7ae64d3acd4cfb92f5564a05f0b0dd4c6dcd9.png)

I only have 1 LAN port connected at the moment as I'm short of switch sockets but it is certainly responding as expected.

> [@GravityRZ](#):
>
> problem with nmap seems to be(with option sn) that it shows up when on but does not show up when off.

That is expected. That's why the flow _should_ be accumulating data and records the last update timestamp. This is certainly working for me. So you may want to go back to my original flow and check what is different in yours.

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [5 March 2020 19:31 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/27 "2020-03-05T19:31:30Z")

</div>

did the whole thing again.

now it seems to stick (getting square eyes from all that code)

my network flows are based on ip address and not mac so i changed the code a bit so instead of having mac entries i now have ip entries

regarding my flow.  
i will go back to my old flow  
ip node, arp node and function node  
combined which the global info from your flow it will give me all the data from my net work as well as a really quick response to see if a device is up and down.

thanks for your help. really nice work

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9e2679f87fcc9d273e52b06174a8d437c823c798.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 March 2020 21:39 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/28 "2020-03-05T21:39:10Z")

</div>

Great stuff, glad things are working.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 March 2020 21:39 UTC](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412/29 "2020-03-19T21:39:22Z")

</div>

Closed on 19 March 2020 21:39 UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/npm-function-network-utils-arp-lookup-weird-promise-output/22412.md?page=1)
