Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not return any MAC addresses when offline #2

Closed
arthurakay opened this issue Jun 18, 2015 · 8 comments
Closed

Does not return any MAC addresses when offline #2

arthurakay opened this issue Jun 18, 2015 · 8 comments
Assignees
Milestone

Comments

@arthurakay
Copy link

I've been using this module in a project, and users have reported problems on various platforms -- the problems all boil down to my use of macaddress, but only when their machines are offline.

I haven't been able to reproduce the issue personally on OSX, but on Windows 8.1 I see the problem.

mac.all(function (err, all) {
    for (var prop in all) {
        console.log(all[ prop ].mac); //will always be blank output when offline
    }
});

To be clear, my Windows 8.1 machine does not have WIFI -- it only uses a hard ethernet connection. Removing that hard line is when I see the issue.

@scravy
Copy link
Owner

scravy commented Jun 27, 2015

I have tested the library in a Windows XP machine and it worked quite well. Which version of node/iojs are you using? Could you give me the output of require('os').networkInterfaces()?

@scravy scravy added the bug label Jun 27, 2015
@arthurakay
Copy link
Author

Using Node v0.10.38 from my Command Prompt, I get the following:

When connected to hardwire internet:

    > require('os').networkInterfaces()
    { Ethernet:
       [ { address: '2601:245:4200:c772:31da:e934:7671:1a70',
           family: 'IPv6',
           internal: false },
         { address: '2601:245:4200:c772:65ed:8db0:3de9:91fd',
           family: 'IPv6',
           internal: false },
         { address: 'fe80::31da:e934:7671:1a70',
           family: 'IPv6',
           internal: false },
         { address: '10.0.0.11',
           family: 'IPv4',
           internal: false } ],
      'Loopback Pseudo-Interface 1':
       [ { address: '::1',
           family: 'IPv6',
           internal: true },
         { address: '127.0.0.1',
           family: 'IPv4',
           internal: true } ],
      'Teredo Tunneling Pseudo-Interface':
       [ { address: '2001:0:5ef5:79fd:c20:1fe:f5ff:fff4',
           family: 'IPv6',
           internal: false },
         { address: 'fe80::c20:1fe:f5ff:fff4',
           family: 'IPv6',
           internal: false } ] }

When I disconnect the hardwire, I see this:

    > require('os').networkInterfaces()
    { 'Loopback Pseudo-Interface 1':
       [ { address: '::1',
           family: 'IPv6',
           internal: true },
         { address: '127.0.0.1',
           family: 'IPv4',
           internal: true } ] }

So yes, this is Node 0.10.x -- but I also notice the problem when running the command from inside the Electron shell, which (I think) runs the latest io.js.

@scravy
Copy link
Owner

scravy commented Jul 1, 2015

Hm, okay. So the way it currently works is:

  • (1) get a list of interfaces via networkInterfaces() (excluding the loopback device)
  • (2) get mac addresses for these, in node 0.12+ they are already reported, if mac address is not reported check using an OS-dependent tool (ifconfig in Unix, etc.).

In your case it fails in (1).

Maybe I should add some means of getting that list of networkInterfaces in an OS-dependent manner if the list in (1) is empty.

@scravy scravy self-assigned this Aug 19, 2015
@arthurakay
Copy link
Author

Just curious if you made any progress on this. I'm finally circling back to the issue myself, so please let me know if there is anything else I can help with.

@scravy
Copy link
Owner

scravy commented Sep 17, 2015

I do not have access to a windows machine right now :-( so I could not start to work on that. It's still on my radar though.

@McPo
Copy link

McPo commented Oct 28, 2016

This is an issue across all OS's (OSX El Capitan, Ubuntu 14.04, Windows 7 and Windows 10).

Heres a method which works across all those listed OS (Its ugly but works).

ifconfig -l                     #OSX
ls /sys/class/net               #UBUNTU
wmic nic get NetConnectionID    #WINDOWS

Loopback Names

lo0                         # OSX
lo                          # UBUNTU
Loopback Pseudo-Interface 1 # WINDOWS

OSX need to remove loopback

require('child_process').exec('ifconfig -l', (error, stdout, stderr) => { console.log(stdout.trim().split(' ')); });

Ubuntu need to remove loopback

 require('child_process').exec('ls /sys/class/net', (error, stdout, stderr) => { console.log(stdout.trim().split('\n')); })

Windows no need to remove loopback and it isn't returned in this command

require('child_process').exec('wmic nic get NetConnectionID', (error, stdout, stderr) => { console.log(stdout.trim().replace(/\s{2,}/g, '\n').split('\n').slice(1))})

@McPo
Copy link

McPo commented Oct 28, 2016

For those suffering this issue. Heres a hacky workaround for the .one() method

static getInterface() {
        const getAllInterfaces = () => {
            if (process.platform === 'darwin') return childProcess.execSync('ifconfig -l').toString().trim().split(' ');
            else if (process.platform === 'win32') return childProcess.execSync('wmic nic get NetConnectionID').toString().trim().replace(/\s{2,}/g, '\n').split('\n').slice(1);
            else return childProcess.execSync('ls /sys/class/net').toString().trim().split('\n');
        };

        const ifaces = getAllInterfaces();
        const alleged = ['eth0', 'eth1', 'en0', 'en1'];
        let iface = ifaces[0];
        for (let i = 0; i < alleged.length; i++) {
            if (ifaces.indexOf(alleged[i]) !== -1) {
                iface = alleged[i];
                break;
            }
        }
        return iface;
    }

Then call

macaddress.one(Utils.getInterface(), (err, mac) => {} ));

It uses the same logic employed by the .one() method (And any of its warts).

Ive tested it on the above platforms and its works fine.

@scravy scravy added this to the 0.5.0 milestone Apr 21, 2020
@scravy scravy added confirmed and removed bug labels Apr 21, 2020
@scravy scravy added the fixed label May 18, 2020
@scravy
Copy link
Owner

scravy commented May 18, 2020

Has been fixed in https://github.com/scravy/node-macaddress/releases/tag/0.5.0 and is releases as 0.5.0

@scravy scravy closed this as completed May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants