Python : Getting MAC address with uuid shows slightly changed MAC of the system
I've been trying to get the MAC address of the machine I'm using with netifaces and uuid python module. I used the following code :
import netifaces
from uuid import getnode as get_mac
interfaces = netifaces.interfaces()
print(interfaces)
for interface in interfaces:
print(netifaces.ifaddresses(interface))
addr = netifaces.ifaddresses(interface)[netifaces.AF_LINK]
print(addr)
mac = get_mac()
mac_up = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
print(mac_up)
The output is :
['1D16676A-E736-4270-9CDC-0DCDC7B75085', '5C842FD7-362A-4303-BC0D-F39D143D8AF6', '12C9575B-0038-4DCA-BD2A-2D14640C6525', '53609BA0-1064-491B-B755-7562C4EEB3FC', '456B16E8-737A-4C1E-8951-CABA44D359DF', '846EE342-7039-11DE-9D20-806E6F6E6963', 'ABB81A2A-BDC5-4F89-827A-E27A0D82A88C', '31A51864-F30F-40D1-8331-10FEFAACA26E', '3D9390CA-7F9D-4BFB-ABD6-606B3564C3CE', '46E22F14-C414-48F8-82EB-D4D5622358B3', '35BF6E1A-628D-4BD4-B5BF-5321069E9CCE']
-1000: ['addr': '00:ff:1d:16:67:6a'], 23: ['addr': 'fe80::c528:fd58:9be9:8210%23', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%23']
['addr': '00:ff:1d:16:67:6a']
-1000: ['addr': '64:5a:04:72:c1:2d'], 23: ['addr': 'fe80::435:1ea7:11b1:86ea%18', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%18']
['addr': '64:5a:04:72:c1:2d']
-1000: ['addr': '26:5a:04:72:c1:2c'], 23: ['addr': 'fe80::5829:37be:c695:e292%16', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%16']
['addr': '26:5a:04:72:c1:2c']
-1000: ['addr': '64:5a:04:72:c1:2c'], 23: ['addr': 'fe80::7808:c894:e16a:3e33%13', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%13'], 2: ['addr': '192.168.1.13', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255']
['addr': '64:5a:04:72:c1:2c']
-1000: ['addr': '74:86:7a:40:c0:d2'], 23: ['addr': 'fe80::6d42:ba39:2a0d:53cf%10', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%10']
['addr': '74:86:7a:40:c0:d2']
-1000: ['addr': ''], 23: ['addr': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': '::1'], 2: ['addr': '127.0.0.1', 'netmask': '255.0.0.0', 'broadcast': '127.255.255.255']
['addr': '']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0'], 23: ['addr': 'fe80::100:7f:fffe%12', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%12']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
64:5A:04:72:C1:2D
I don't want to use (used once here to test) uuid module as it can give random 48 bit integer (when it couldn't find the MAC address) which may be some fake MAC address. The problem is when I check the MAC address manually from "Network and Sharing Center" in Control Panel, it shows this :
My questions are :
(i) Why uuid fetched mac address is little bit changed at last?
(ii) The list of netifaces.interfaces() shown here is not similar to the one in the documentation of netifaces like ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']? Here the fourth address printed by the loop is the right and current MAC address.
The fourth instance of netifaces.ifaddresses(interface) dictionary has an extra key-value pair with key as 2 which is AF_INET (normal Internet addresses). Is it the right process to get the current right MAC address that we check whether this AF_INET is present in the netifaces.ifaddresses(interface) and then get the netifaces.ifaddresses(interface) ?
python python-3.x uuid python-netifaces
add a comment |
I've been trying to get the MAC address of the machine I'm using with netifaces and uuid python module. I used the following code :
import netifaces
from uuid import getnode as get_mac
interfaces = netifaces.interfaces()
print(interfaces)
for interface in interfaces:
print(netifaces.ifaddresses(interface))
addr = netifaces.ifaddresses(interface)[netifaces.AF_LINK]
print(addr)
mac = get_mac()
mac_up = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
print(mac_up)
The output is :
['1D16676A-E736-4270-9CDC-0DCDC7B75085', '5C842FD7-362A-4303-BC0D-F39D143D8AF6', '12C9575B-0038-4DCA-BD2A-2D14640C6525', '53609BA0-1064-491B-B755-7562C4EEB3FC', '456B16E8-737A-4C1E-8951-CABA44D359DF', '846EE342-7039-11DE-9D20-806E6F6E6963', 'ABB81A2A-BDC5-4F89-827A-E27A0D82A88C', '31A51864-F30F-40D1-8331-10FEFAACA26E', '3D9390CA-7F9D-4BFB-ABD6-606B3564C3CE', '46E22F14-C414-48F8-82EB-D4D5622358B3', '35BF6E1A-628D-4BD4-B5BF-5321069E9CCE']
-1000: ['addr': '00:ff:1d:16:67:6a'], 23: ['addr': 'fe80::c528:fd58:9be9:8210%23', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%23']
['addr': '00:ff:1d:16:67:6a']
-1000: ['addr': '64:5a:04:72:c1:2d'], 23: ['addr': 'fe80::435:1ea7:11b1:86ea%18', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%18']
['addr': '64:5a:04:72:c1:2d']
-1000: ['addr': '26:5a:04:72:c1:2c'], 23: ['addr': 'fe80::5829:37be:c695:e292%16', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%16']
['addr': '26:5a:04:72:c1:2c']
-1000: ['addr': '64:5a:04:72:c1:2c'], 23: ['addr': 'fe80::7808:c894:e16a:3e33%13', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%13'], 2: ['addr': '192.168.1.13', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255']
['addr': '64:5a:04:72:c1:2c']
-1000: ['addr': '74:86:7a:40:c0:d2'], 23: ['addr': 'fe80::6d42:ba39:2a0d:53cf%10', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%10']
['addr': '74:86:7a:40:c0:d2']
-1000: ['addr': ''], 23: ['addr': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': '::1'], 2: ['addr': '127.0.0.1', 'netmask': '255.0.0.0', 'broadcast': '127.255.255.255']
['addr': '']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0'], 23: ['addr': 'fe80::100:7f:fffe%12', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%12']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
64:5A:04:72:C1:2D
I don't want to use (used once here to test) uuid module as it can give random 48 bit integer (when it couldn't find the MAC address) which may be some fake MAC address. The problem is when I check the MAC address manually from "Network and Sharing Center" in Control Panel, it shows this :
My questions are :
(i) Why uuid fetched mac address is little bit changed at last?
(ii) The list of netifaces.interfaces() shown here is not similar to the one in the documentation of netifaces like ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']? Here the fourth address printed by the loop is the right and current MAC address.
The fourth instance of netifaces.ifaddresses(interface) dictionary has an extra key-value pair with key as 2 which is AF_INET (normal Internet addresses). Is it the right process to get the current right MAC address that we check whether this AF_INET is present in the netifaces.ifaddresses(interface) and then get the netifaces.ifaddresses(interface) ?
python python-3.x uuid python-netifaces
add a comment |
I've been trying to get the MAC address of the machine I'm using with netifaces and uuid python module. I used the following code :
import netifaces
from uuid import getnode as get_mac
interfaces = netifaces.interfaces()
print(interfaces)
for interface in interfaces:
print(netifaces.ifaddresses(interface))
addr = netifaces.ifaddresses(interface)[netifaces.AF_LINK]
print(addr)
mac = get_mac()
mac_up = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
print(mac_up)
The output is :
['1D16676A-E736-4270-9CDC-0DCDC7B75085', '5C842FD7-362A-4303-BC0D-F39D143D8AF6', '12C9575B-0038-4DCA-BD2A-2D14640C6525', '53609BA0-1064-491B-B755-7562C4EEB3FC', '456B16E8-737A-4C1E-8951-CABA44D359DF', '846EE342-7039-11DE-9D20-806E6F6E6963', 'ABB81A2A-BDC5-4F89-827A-E27A0D82A88C', '31A51864-F30F-40D1-8331-10FEFAACA26E', '3D9390CA-7F9D-4BFB-ABD6-606B3564C3CE', '46E22F14-C414-48F8-82EB-D4D5622358B3', '35BF6E1A-628D-4BD4-B5BF-5321069E9CCE']
-1000: ['addr': '00:ff:1d:16:67:6a'], 23: ['addr': 'fe80::c528:fd58:9be9:8210%23', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%23']
['addr': '00:ff:1d:16:67:6a']
-1000: ['addr': '64:5a:04:72:c1:2d'], 23: ['addr': 'fe80::435:1ea7:11b1:86ea%18', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%18']
['addr': '64:5a:04:72:c1:2d']
-1000: ['addr': '26:5a:04:72:c1:2c'], 23: ['addr': 'fe80::5829:37be:c695:e292%16', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%16']
['addr': '26:5a:04:72:c1:2c']
-1000: ['addr': '64:5a:04:72:c1:2c'], 23: ['addr': 'fe80::7808:c894:e16a:3e33%13', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%13'], 2: ['addr': '192.168.1.13', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255']
['addr': '64:5a:04:72:c1:2c']
-1000: ['addr': '74:86:7a:40:c0:d2'], 23: ['addr': 'fe80::6d42:ba39:2a0d:53cf%10', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%10']
['addr': '74:86:7a:40:c0:d2']
-1000: ['addr': ''], 23: ['addr': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': '::1'], 2: ['addr': '127.0.0.1', 'netmask': '255.0.0.0', 'broadcast': '127.255.255.255']
['addr': '']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0'], 23: ['addr': 'fe80::100:7f:fffe%12', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%12']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
64:5A:04:72:C1:2D
I don't want to use (used once here to test) uuid module as it can give random 48 bit integer (when it couldn't find the MAC address) which may be some fake MAC address. The problem is when I check the MAC address manually from "Network and Sharing Center" in Control Panel, it shows this :
My questions are :
(i) Why uuid fetched mac address is little bit changed at last?
(ii) The list of netifaces.interfaces() shown here is not similar to the one in the documentation of netifaces like ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']? Here the fourth address printed by the loop is the right and current MAC address.
The fourth instance of netifaces.ifaddresses(interface) dictionary has an extra key-value pair with key as 2 which is AF_INET (normal Internet addresses). Is it the right process to get the current right MAC address that we check whether this AF_INET is present in the netifaces.ifaddresses(interface) and then get the netifaces.ifaddresses(interface) ?
python python-3.x uuid python-netifaces
I've been trying to get the MAC address of the machine I'm using with netifaces and uuid python module. I used the following code :
import netifaces
from uuid import getnode as get_mac
interfaces = netifaces.interfaces()
print(interfaces)
for interface in interfaces:
print(netifaces.ifaddresses(interface))
addr = netifaces.ifaddresses(interface)[netifaces.AF_LINK]
print(addr)
mac = get_mac()
mac_up = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
print(mac_up)
The output is :
['1D16676A-E736-4270-9CDC-0DCDC7B75085', '5C842FD7-362A-4303-BC0D-F39D143D8AF6', '12C9575B-0038-4DCA-BD2A-2D14640C6525', '53609BA0-1064-491B-B755-7562C4EEB3FC', '456B16E8-737A-4C1E-8951-CABA44D359DF', '846EE342-7039-11DE-9D20-806E6F6E6963', 'ABB81A2A-BDC5-4F89-827A-E27A0D82A88C', '31A51864-F30F-40D1-8331-10FEFAACA26E', '3D9390CA-7F9D-4BFB-ABD6-606B3564C3CE', '46E22F14-C414-48F8-82EB-D4D5622358B3', '35BF6E1A-628D-4BD4-B5BF-5321069E9CCE']
-1000: ['addr': '00:ff:1d:16:67:6a'], 23: ['addr': 'fe80::c528:fd58:9be9:8210%23', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%23']
['addr': '00:ff:1d:16:67:6a']
-1000: ['addr': '64:5a:04:72:c1:2d'], 23: ['addr': 'fe80::435:1ea7:11b1:86ea%18', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%18']
['addr': '64:5a:04:72:c1:2d']
-1000: ['addr': '26:5a:04:72:c1:2c'], 23: ['addr': 'fe80::5829:37be:c695:e292%16', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%16']
['addr': '26:5a:04:72:c1:2c']
-1000: ['addr': '64:5a:04:72:c1:2c'], 23: ['addr': 'fe80::7808:c894:e16a:3e33%13', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%13'], 2: ['addr': '192.168.1.13', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255']
['addr': '64:5a:04:72:c1:2c']
-1000: ['addr': '74:86:7a:40:c0:d2'], 23: ['addr': 'fe80::6d42:ba39:2a0d:53cf%10', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%10']
['addr': '74:86:7a:40:c0:d2']
-1000: ['addr': ''], 23: ['addr': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': '::1'], 2: ['addr': '127.0.0.1', 'netmask': '255.0.0.0', 'broadcast': '127.255.255.255']
['addr': '']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0'], 23: ['addr': 'fe80::100:7f:fffe%12', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%12']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
-1000: ['addr': '00:00:00:00:00:00:00:e0']
['addr': '00:00:00:00:00:00:00:e0']
64:5A:04:72:C1:2D
I don't want to use (used once here to test) uuid module as it can give random 48 bit integer (when it couldn't find the MAC address) which may be some fake MAC address. The problem is when I check the MAC address manually from "Network and Sharing Center" in Control Panel, it shows this :
My questions are :
(i) Why uuid fetched mac address is little bit changed at last?
(ii) The list of netifaces.interfaces() shown here is not similar to the one in the documentation of netifaces like ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']? Here the fourth address printed by the loop is the right and current MAC address.
The fourth instance of netifaces.ifaddresses(interface) dictionary has an extra key-value pair with key as 2 which is AF_INET (normal Internet addresses). Is it the right process to get the current right MAC address that we check whether this AF_INET is present in the netifaces.ifaddresses(interface) and then get the netifaces.ifaddresses(interface) ?
python python-3.x uuid python-netifaces
python python-3.x uuid python-netifaces
asked Nov 14 '18 at 6:28
michael petronavmichael petronav
1931218
1931218
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294279%2fpython-getting-mac-address-with-uuid-shows-slightly-changed-mac-of-the-system%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294279%2fpython-getting-mac-address-with-uuid-shows-slightly-changed-mac-of-the-system%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown