Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e66bb969
Kaydet (Commit)
e66bb969
authored
Kas 07, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17293: uuid.getnode() now determines MAC address on AIX using netstat.
Based on patch by Aivars Kalvāns.
üst
8e92f572
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
19 deletions
+71
-19
test_uuid.py
Lib/test/test_uuid.py
+18
-0
uuid.py
Lib/uuid.py
+50
-19
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_uuid.py
Dosyayı görüntüle @
e66bb969
...
...
@@ -319,6 +319,24 @@ class TestUUID(unittest.TestCase):
if
node
is
not
None
:
self
.
check_node
(
node
,
'ifconfig'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_arp_getnode
(
self
):
node
=
uuid
.
_arp_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'arp'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_lanscan_getnode
(
self
):
node
=
uuid
.
_lanscan_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'lanscan'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_netstat_getnode
(
self
):
node
=
uuid
.
_netstat_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'netstat'
)
@unittest.skipUnless
(
os
.
name
==
'nt'
,
'requires Windows'
)
def
test_ipconfig_getnode
(
self
):
node
=
uuid
.
_ipconfig_getnode
()
...
...
Lib/uuid.py
Dosyayı görüntüle @
e66bb969
...
...
@@ -311,7 +311,7 @@ class UUID(object):
if
self
.
variant
==
RFC_4122
:
return
int
((
self
.
int
>>
76
)
&
0xf
)
def
_
find_mac
(
command
,
args
,
hw_identifiers
,
get_index
):
def
_
popen
(
command
,
args
):
import
os
,
shutil
executable
=
shutil
.
which
(
command
)
if
executable
is
None
:
...
...
@@ -319,20 +319,27 @@ def _find_mac(command, args, hw_identifiers, get_index):
executable
=
shutil
.
which
(
command
,
path
=
path
)
if
executable
is
None
:
return
None
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd
=
'LC_ALL=C
%
s
%
s 2>/dev/null'
%
(
executable
,
args
)
return
os
.
popen
(
cmd
)
def
_find_mac
(
command
,
args
,
hw_identifiers
,
get_index
):
try
:
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd
=
'LC_ALL=C
%
s
%
s 2>/dev/null'
%
(
executable
,
args
)
with
os
.
popen
(
cmd
)
as
pipe
:
pipe
=
_popen
(
command
,
args
)
if
not
pipe
:
return
with
pipe
:
for
line
in
pipe
:
words
=
line
.
lower
()
.
split
()
words
=
line
.
lower
()
.
rstrip
()
.
split
()
for
i
in
range
(
len
(
words
)):
if
words
[
i
]
in
hw_identifiers
:
try
:
return
int
(
words
[
get_index
(
i
)]
.
replace
(
':'
,
''
),
16
)
word
=
words
[
get_index
(
i
)]
mac
=
int
(
word
.
replace
(
':'
,
''
),
16
)
if
mac
:
return
mac
except
(
ValueError
,
IndexError
):
# Virtual interfaces, such as those provided by
# VPNs, do not have a colon-delimited MAC address
...
...
@@ -345,27 +352,50 @@ def _find_mac(command, args, hw_identifiers, get_index):
def
_ifconfig_getnode
():
"""Get the hardware address on Unix by running ifconfig."""
# This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
for
args
in
(
''
,
'-a'
,
'-av'
):
mac
=
_find_mac
(
'ifconfig'
,
args
,
[
'hwaddr'
,
'ether'
],
lambda
i
:
i
+
1
)
if
mac
:
return
mac
import
socket
def
_arp_getnode
():
"""Get the hardware address on Unix by running arp."""
import
os
,
socket
ip_addr
=
socket
.
gethostbyname
(
socket
.
gethostname
())
# Try getting the MAC addr from arp based on our IP address (Solaris).
mac
=
_find_mac
(
'arp'
,
'-an'
,
[
ip_addr
],
lambda
i
:
-
1
)
if
mac
:
return
mac
return
_find_mac
(
'arp'
,
'-an'
,
[
ip_addr
],
lambda
i
:
-
1
)
def
_lanscan_getnode
():
"""Get the hardware address on Unix by running lanscan."""
# This might work on HP-UX.
mac
=
_find_mac
(
'lanscan'
,
'-ai'
,
[
'lan0'
],
lambda
i
:
0
)
if
mac
:
return
mac
return
_find_mac
(
'lanscan'
,
'-ai'
,
[
'lan0'
],
lambda
i
:
0
)
return
None
def
_netstat_getnode
():
"""Get the hardware address on Unix by running netstat."""
# This might work on AIX, Tru64 UNIX and presumably on IRIX.
try
:
pipe
=
_popen
(
'netstat'
,
'-ia'
)
if
not
pipe
:
return
with
pipe
:
words
=
pipe
.
readline
()
.
rstrip
()
.
split
()
try
:
i
=
words
.
index
(
'Address'
)
except
ValueError
:
return
for
line
in
pipe
:
try
:
words
=
line
.
rstrip
()
.
split
()
word
=
words
[
i
]
if
len
(
word
)
==
17
and
word
.
count
(
':'
)
==
5
:
mac
=
int
(
word
.
replace
(
':'
,
''
),
16
)
if
mac
:
return
mac
except
(
ValueError
,
IndexError
):
pass
except
OSError
:
pass
def
_ipconfig_getnode
():
"""Get the hardware address on Windows by running ipconfig.exe."""
...
...
@@ -506,7 +536,8 @@ def getnode():
if
sys
.
platform
==
'win32'
:
getters
=
[
_windll_getnode
,
_netbios_getnode
,
_ipconfig_getnode
]
else
:
getters
=
[
_unixdll_getnode
,
_ifconfig_getnode
]
getters
=
[
_unixdll_getnode
,
_ifconfig_getnode
,
_arp_getnode
,
_lanscan_getnode
,
_netstat_getnode
]
for
getter
in
getters
+
[
_random_getnode
]:
try
:
...
...
Misc/NEWS
Dosyayı görüntüle @
e66bb969
...
...
@@ -36,6 +36,9 @@ Core and Builtins
Library
-------
- Issue #17293: uuid.getnode() now determines MAC address on AIX using netstat.
Based on patch by Aivars Kalvāns.
- Issue #22769: Fixed ttk.Treeview.tag_has() when called without arguments.
- Issue #22417: Verify certificates by default in httplib (PEP 476).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment