Code Monkey home page Code Monkey logo

Comments (5)

skydiver avatar skydiver commented on May 24, 2024

Hello @scInvest

To get the arp table, you can just do:

const Zeroconf = require('ewelink-api/classes/Zeroconf');
const arp = await Zeroconf.getArpTable('192.168.5.1');

To get devices data:

const connection = new ewelink({
  email: 'user',
  password: 'pass',
});
const devices = connection this.getDevices();

Then you can use arp and devices to connect.

from ewelink-api.

ttz642 avatar ttz642 commented on May 24, 2024

await connection.saveDevicesCache();
works, but:
const arp = await Zeroconf.getArpTable('192.168.1.1');
returns nothing...
Can you show example of the json structure saved in the file and I'll create my own while I figure out why its not working.

I'll create from the avahi-browse:
avahi

from ewelink-api.

skydiver avatar skydiver commented on May 24, 2024

@ttz642:

There was a problem with the arp package who was fixed and merged today.

Here is the expected format:

[
  {
    "ip": "192.168.100.1",
    "mac": "aa:bb:cc:dd:ee:ff"
  },
  {
    "ip": "192.168.100.2",
    "mac": "aa:bb:cc:dd:ee:ee"
  }
]

from ewelink-api.

ttz642 avatar ttz642 commented on May 24, 2024

There was a problem with the arp package who was fixed and merged today.

I just removed the release 2 branch I'd installed and re-installed the master branch which is the 2.0.0 release (including fix I assume).

Still doesn't work (for me).

I'm using ubuntu 18.04 (will update to 20.04 when released).

from ewelink-api.

ttz642 avatar ttz642 commented on May 24, 2024

I haven't looked through the code just yet but I'm guessing the ArpTable is used to map the mac address to the ip.

What your really after is what is the ip address of the device id, I assume your looking for the mac address in the device cache then looking for the ip address in the ArpTable.

What you really want is a table mapping device id's to ip addresses.

The following linux command:

avahi-browse -arlcfp | grep -P '^=' |  grep "eWeLink" \
	| pcre2grep -o2 -o1 -i --om-separator='|' 'local;eWeLink_(1000[0-9a-f]{6}).local;(192.168.1\..+);8081;' \
	| gawk -F '|' -e 'BEGIN{print "{";li="";}{printf li"  \"%s\": \"%s\"",$2,$1;li=",\n";}END{print "\n}";}' \
	> deviceip-table.json

creates the json file deviceip-table.json, which contains:

{
  "1000xxxxxx": "192.168.1.233",
  "1000xxxxxx": "192.168.1.220",
  "1000xxxxxx": "192.168.1.238",
  "1000xxxxxx": "192.168.1.237",
  "1000xxxxxx": "192.168.1.202",
  "1000xxxxxx": "192.168.1.249",
  "1000xxxxxx": "192.168.1.227"
}

Therefore if the json is read into an array deviceIP all we need to do to resolve the ip address is use the device id, ie:
deviceIP[<deviceid>]
BTW: avahi-browse works best when the devices are disconnected from the WAN as the devices broadcast their availability more often. OR launch the eWeLink app on your phone and enter LAN mode which somehow probes the LAN.

To create the table as currently execute the following script:

TMP=`mktemp -d`

avahi-browse -arlcfp | grep -P '^=' |  grep "eWeLink" \
	| pcre2grep  -o2 -i  'local;eWeLink_(1000[0-9a-f]{6}).local;(192.168.1\..+);8081;' \
	| sort | tee $TMP/ewedev | gawk -F '|' -e '{print "ping  -n -c 3 "$1}' | bash

/usr/sbin/arp -an | pcre2grep -o1 -o2 -i --om-separator='|' '\? \((.*)\) at (.*) \[ether\]' | sort > $TMP/ipmac

join -t '|' $TMP/ipmac $TMP/ewedev \
	| gawk -F '|' -e 'BEGIN{print "[";li="";}{printf li"  {\n    \"ip\":\"%s\",\n    \"mac\":\"%s\"\n  }",$1,$2;li=",\n";}END{print "\n}";}' \
	> arp-table.json

rm -rf $TMP

from ewelink-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.