Get the hardware address on Unix by running arp.
()
| 591 | return None |
| 592 | |
| 593 | def _arp_getnode(): |
| 594 | """Get the hardware address on Unix by running arp.""" |
| 595 | import os, socket |
| 596 | if not hasattr(socket, "gethostbyname"): |
| 597 | return None |
| 598 | try: |
| 599 | ip_addr = socket.gethostbyname(socket.gethostname()) |
| 600 | except OSError: |
| 601 | return None |
| 602 | |
| 603 | # Try getting the MAC addr from arp based on our IP address (Solaris). |
| 604 | mac = _find_mac_near_keyword('arp', '-an', [os.fsencode(ip_addr)], lambda i: -1) |
| 605 | if mac: |
| 606 | return mac |
| 607 | |
| 608 | # This works on OpenBSD |
| 609 | mac = _find_mac_near_keyword('arp', '-an', [os.fsencode(ip_addr)], lambda i: i+1) |
| 610 | if mac: |
| 611 | return mac |
| 612 | |
| 613 | # This works on Linux, FreeBSD and NetBSD |
| 614 | mac = _find_mac_near_keyword('arp', '-an', [os.fsencode('(%s)' % ip_addr)], |
| 615 | lambda i: i+2) |
| 616 | # Return None instead of 0. |
| 617 | if mac: |
| 618 | return mac |
| 619 | return None |
| 620 | |
| 621 | def _lanscan_getnode(): |
| 622 | """Get the hardware address on Unix by running lanscan.""" |
nothing calls this directly
no test coverage detected
searching dependent graphs…