• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get host MAC via REST API inside container
#1
Hi all,

we need the MAC address of the host system inside a container on the Hilscher netPI.
For me it seemed to be a suitable solution to get the LAN settings, and also the MAC, from the Hilscher REST API.

As described in this thread, we first logged in with the admin user to get the authentication cookie.

Code:
curl -L -k -X POST 'https://<HOST-IP>/login' -H 'Content-Type: application/json' -d '{"username":"admin","password":"<PASSWORD>"}'


With the authentication cookie we are able to get various information from the API. The following requests all worked.
Code:
curl -L -k -X GET 'htps://<HOST-IP>/?page=infocenter' -H 'Cookie: <COOKIE>'

Code:
curl -L -k -X GET 'htps://<HOST-IP>/get/devicestatus/getCPUStatus' -H 'Cookie: <COOKIE>'

Code:
curl -L -k -X POST 'https://<HOST-IP>/system' --header 'Cookie: <COOKIE>; Content-Type: application/x-www-form-urlencoded' -d "argument=reboot"


But the request to get the LAN settings always responds the following:
Code:
{"status":"Failed","message":"Permission denied"}


Here's the request as we tried:
Code:
curl -L -k -X GET 'htps://<HOST-IP>/get/networksettings/lansettings' -H 'Cookie: <COOKIE>'

The admin user has all read & write rights in the application, also for the REST API.


Can anyone imagine what we are doing wrong here?

Is this a good way to get the MAC-address of the host system or is there a better solution?

Many thanks in advance.

Best regards
Benjamin
  Reply
#2
Well I would do it differently.

You need to know that the MAC address of a Raspberry Pi is starting always with B8:27:EB which is the vendor ID of the Raspberry Pi organization followed by the 6 last digits (3 bytes) of the serial number of Raspberry Pi CPU. This adds to 6 bytes

So with this knowledge you could easily build the MAC address your own without reading it across the web-UI.

This code below should help you to extract the CPU's serial number which should also work in a container I guess

Code:
cat /proc/cpuinfo |grep Serial|cut -d' ' -f2


Thx
Armin
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#3
Thanks a lot! This is a suitable approach for us, at least in the current version.
Is this structure of the MAC (OUI + last 3 bytes of the cpu serial nr.) a Raspberry or Hilscher speciality?
How about the netPI RTE module with multiple NICs?

Can you imagine why the GET request for LAN settings (see above) did not work?
We would like to use the REST API for other topics as well.

Best regards
Benjamin
  Reply
#4
Hi Benjamin,

the point with the MAC ID is common Raspberry Pi sense and not Hilscher specific. You can use google search to find several links where this is described.


As next I want to give you a hint how you can test any RESTful API yourself using a browser like google chrome for example. It works with Firefox as well.

Any modern browser has the option to enable debugging HTML web pages. So as with google chrome. So visit the netPI main page and choose from the chrome browser's three dots in the upper right corner the option "tools/development tools ... ". A new window will be opened next to the netPI web page.

In this window you have several tabs you can choose to look into, the most important one for you is the "network" tab. In this tab all the web browser's API calls to the netPI web pages are recorded message by message. So now login to netPI as usual ... you will see the requested login message being recorded under "headers" and you see also the response from netPI under "response" and the cookie. You should see basically the very same messages as those you call via the curl command. Then go on further to other netPI web sites you want to get recorded and analyse them ... by this method you will get out where your problem is with ease.

Thx
Armin
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NIOT-E-NPIX-4DI4DO with netpi-netx container WalterSchaefer 2 97 October-17th-2020, 07:59 PM
Last Post: WalterSchaefer
  Exporting and importing container images Armin@netPI 3 269 May-20th-2020, 11:24 AM
Last Post: COswald
Exclamation Creating a container Linnerz 6 414 March-6th-2020, 02:47 PM
Last Post: Armin@netPI
  [SOLVED] activate LED1/2 with Node-RED + fieldbus nodes container Christian_Rau 6 397 October-21st-2019, 10:30 AM
Last Post: Armin@netPI
  Cannot start container Magnus 7 425 October-16th-2019, 01:00 PM
Last Post: Armin@netPI
  Generate VLAN interfaces in container FrankJacob 7 306 September-26th-2019, 03:19 PM
Last Post: Armin@netPI
  create container in Portainer v1.12.4 dcatteeu 2 233 September-9th-2019, 12:12 PM
Last Post: dcatteeu
  UMTS/LTE support via USB router/modem sticks in a container Armin@netPI 3 321 September-5th-2019, 02:07 PM
Last Post: Armin@netPI
  Ready-to-deploy: full featured Node-RED container Armin@netPI 5 388 July-25th-2019, 06:16 AM
Last Post: Armin@netPI
Information netPI Docker REST API for versions >= V1.1.4.0 patrick 1 311 July-16th-2019, 02:45 PM
Last Post: patrick

Forum Jump:


Users browsing this thread: 1 Guest(s)