Skip to content

[BUG] On collect always error 'failed to find MAC address with IP' #92

@joseangel-gomez

Description

@joseangel-gomez

bug

In my system the "collect" command always gives error failed to find MAC address with IP

version

commit fcfe76295e4759abcf4596f7c2d7eacb9244c253 (HEAD -> main, tag: v0.2.1, origin/main, origin/HEAD)
Merge: 2fca8f9 cc6ab50

To Reproduce

Steps to reproduce the behavior:

  1. ./magellan scan --subnet 192.168.10.0 --subnet-mask 255.255.255.0 --cache data/assets.db
  2. ./magellan list --cache data/assets.db
  3. ./magellan collect --cache data/assets.db --timeout 5 --username root --password 0penBmc --output logs

And I see these errors

{"level":"warn","error":"no ethernet interfaces found with IP address","time":"2025-04-25T16:32:21+02:00","message":"failed to find MAC address with IP 'https://192.168.10.46'"}
{"level":"warn","error":"no ethernet interfaces found with IP address","time":"2025-04-25T16:32:21+02:00","message":"failed to find MAC address with IP 'https://192.168.10.91'"}
{"level":"warn","error":"no ethernet interfaces found with IP address","time":"2025-04-25T16:32:23+02:00","message":"failed to find MAC address with IP 'https://192.168.10.82'"}
{"level":"warn","error":"no ethernet interfaces found with IP address","time":"2025-04-25T16:32:23+02:00","message":"failed to find MAC address with IP 'https://192.168.10.85'"}

See the complete traces in the file below (traces.error.txt)

and

$ sqlite3
SQLite version 3.26.0 2018-12-01 12:34:55
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> attach "/playground/magellan/data/assets.db" as db1;
sqlite> .tables
db1.magellan_scanned_assets
sqlite> SELECT * FROM db1.magellan_scanned_assets;
https://192.168.10.86|443|tcp|1|2025-04-25 16:31:34.732021656+02:00
https://192.168.10.91|443|tcp|1|2025-04-25 16:31:34.732903915+02:00
https://192.168.10.46|443|tcp|1|2025-04-25 16:31:34.733949108+02:00
https://192.168.10.82|443|tcp|1|2025-04-25 16:31:34.731715066+02:00
https://192.168.10.85|443|tcp|1|2025-04-25 16:31:34.731943185+02:00
https://192.168.10.25|443|tcp|1|2025-04-25 16:31:34.732430844+02:00
sqlite> 

Fix

The problem is that the IP is stored with the HTTPS prefix, https://192.168.10.85 , but the function expects only the IP, 192.168.10.85.

This patch fixes the error:

$ git diff pkg/collect.go
diff --git a/pkg/collect.go b/pkg/collect.go
index 69fe951..862ea3c 100644
--- a/pkg/collect.go
+++ b/pkg/collect.go
@@ -167,7 +167,14 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) ([]map[strin
 
                                // optionally, add the MACAddr property if we find a matching IP
                                // from the correct ethernet interface
-                               mac, err := FindMACAddressWithIP(config, net.ParseIP(sr.Host))
+                               host := sr.Host
+                               sub_str := "https://"
+                               if strings.Contains(host, sub_str) {
+                                       host = strings.TrimPrefix(sr.Host,sub_str)
+                               }
+
+                               mac, err := FindMACAddressWithIP(config, net.ParseIP(host))
+                               // mac, err := FindMACAddressWithIP(config, net.ParseIP(sr.Host))
                                if err != nil {
                                        log.Warn().Err(err).Msgf("failed to find MAC address with IP '%s'", sr.Host)
                                }
(END)

See the complete traces in the file below (traces.fix.txt)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions