-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacaddr
executable file
·207 lines (171 loc) · 10.4 KB
/
macaddr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
# Author: Doug Rudolph (github.com/11)
# Date: Mar. 21, 2024
# Description: MAC address spoofer for macbooks
import sys
import subprocess
import time
import socket
from argparse import ArgumentParser, BooleanOptionalAction
from typing import List, TypedDict
from random import randint
apple_mac_address_prefixes = [
0x000393, 0x000A27, 0x000A95, 0x000D93, 0x0010FA, 0x001124, 0x001451, 0x0016CB, 0x0017F2, 0x0019E3, 0x001B63, 0x001CB3, 0x001D4F, 0x001E52, 0x001EC2, 0x001F5B, 0x001FF3, 0x0021E9, 0x002241,
0x002312, 0x002332, 0x00236C, 0x0023DF, 0x002436, 0x002500, 0x00254B, 0x0025BC, 0x002608, 0x00264A, 0x0026B0, 0x0026BB, 0x003065, 0x003EE1, 0x0050E4, 0x0056CD, 0x006171, 0x006D52, 0x008865,
0x00B362, 0x00C610, 0x00CDFE, 0x00F4B9, 0x00F76F, 0x040CCE, 0x041552, 0x041E64, 0x042665, 0x04489A, 0x044BED, 0x0452F3, 0x045453, 0x0469F8, 0x04D3CF, 0x04DB56, 0x04E536, 0x04F13E, 0x04F7E4,
0x086698, 0x086D41, 0x087045, 0x087402, 0x0C1539, 0x0C3021, 0x0C3E9F, 0x0C4DE9, 0x0C5101, 0x0C74C2, 0x0C771A, 0x0CBC9F, 0x0CD746, 0x101C0C, 0x1040F3, 0x10417F, 0x1093E9, 0x109ADD, 0x10DDB1,
0x14109F, 0x145A05, 0x148FC6, 0x1499E2, 0x14BD61, 0x182032, 0x183451, 0x186590, 0x189EFC, 0x18AF61, 0x18AF8F, 0x18E7F4, 0x18EE69, 0x18F643, 0x1C1AC0, 0x1C5CF2, 0x1C9148, 0x1C9E46, 0x1CABA7,
0x1CE62B, 0x203CAE, 0x20768F, 0x2078F0, 0x207D74, 0x209BCD, 0x20A2E4, 0x20AB37, 0x20C9D0, 0x241EEB, 0x24240E, 0x245BA7, 0x24A074, 0x24A2E1, 0x24AB81, 0x24E314, 0x24F094, 0x280B5C, 0x283737,
0x285AEB, 0x286AB8, 0x286ABA, 0x28A02B, 0x28CFDA, 0x28CFE9, 0x28E02C, 0x28E14C, 0x28E7CF, 0x28ED6A, 0x28F076, 0x2C1F23, 0x2C200B, 0x2C3361, 0x2CB43A, 0x2CBE08, 0x2CF0A2, 0x2CF0EE, 0x3010E4,
0x30636B, 0x3090AB, 0x30F7C5, 0x341298, 0x34159E, 0x34363B, 0x3451C9, 0x34A395, 0x34AB37, 0x34C059, 0x34E2FD, 0x380F4A, 0x38484C, 0x3871DE, 0x38B54D, 0x38C986, 0x38CADA, 0x3C0754, 0x3C15C2,
0x3CAB8E, 0x3CD0F8, 0x3CE072, 0x403004, 0x40331A, 0x403CFC, 0x404D7F, 0x406C8F, 0x40A6D9, 0x40B395, 0x40D32D, 0x440010, 0x442A60, 0x444C0C, 0x44D884, 0x44FB42, 0x483B38, 0x48437C, 0x484BAA,
0x4860BC, 0x48746E, 0x48A195, 0x48BF6B, 0x48D705, 0x48E9F1, 0x4C3275, 0x4C57CA, 0x4C74BF, 0x4C7C5F, 0x4C8D79, 0x4CB199, 0x503237, 0x507A55, 0x5082D5, 0x50EAD6, 0x542696, 0x544E90, 0x54724F,
0x549F13, 0x54AE27, 0x54E43A, 0x54EAA8, 0x581FAA, 0x58404E, 0x5855CA, 0x587F57, 0x58B035, 0x5C5948, 0x5C8D4E, 0x5C95AE, 0x5C969D, 0x5C97F3, 0x5CADCF, 0x5CF5DA, 0x5CF7E6, 0x5CF938, 0x600308,
0x60334B, 0x606944, 0x609217, 0x609AC1, 0x60A37D, 0x60C547, 0x60D9C7, 0x60F445, 0x60F81D, 0x60FACD, 0x60FB42, 0x60FEC5, 0x64200C, 0x6476BA, 0x649ABE, 0x64A3CB, 0x64A5C3, 0x64B0A6, 0x64B9E8,
0x64E682, 0x680927, 0x685B35, 0x68644B, 0x68967B, 0x689C70, 0x68A86D, 0x68AE20, 0x68D93C, 0x68DBCA, 0x68FB7E, 0x6C19C0, 0x6C3E6D, 0x6C4008, 0x6C709F, 0x6C72E7, 0x6C8DC1, 0x6C94F8, 0x6CAB31,
0x6CC26B, 0x701124, 0x7014A6, 0x703EAC, 0x70480F, 0x705681, 0x70700D, 0x7073CB, 0x7081EB, 0x70A2B3, 0x70CD60, 0x70DEE2, 0x70E72C, 0x70ECE4, 0x70F087, 0x741BB2, 0x748114, 0x748D08, 0x74E1B6,
0x74E2F5, 0x7831C1, 0x783A84, 0x784F43, 0x786C1C, 0x787E61, 0x789F70, 0x78A3E4, 0x78CA39, 0x78D75F, 0x78FD94, 0x7C0191, 0x7C04D0, 0x7C11BE, 0x7C5049, 0x7C6D62, 0x7C6DF8, 0x7CC3A1, 0x7CC537,
0x7CD1C3, 0x7CF05F, 0x7CFADF, 0x80006E, 0x804971, 0x80929F, 0x80BE05, 0x80D605, 0x80E650, 0x80EA96, 0x80ED2C, 0x842999, 0x843835, 0x84788B, 0x848506, 0x8489AD, 0x848E0C, 0x84A134, 0x84B153,
0x84FCAC, 0x84FCFE, 0x881FA1, 0x885395, 0x8863DF, 0x8866A5, 0x886B6E, 0x88C663, 0x88CB87, 0x88E87F, 0x8C006D, 0x8C2937, 0x8C2DAA, 0x8C5877, 0x8C7B9D, 0x8C7C92, 0x8C8EF2, 0x8C8FE9, 0x8CFABA,
0x9027E4, 0x903C92, 0x9060F1, 0x907240, 0x90840D, 0x908D6C, 0x90B0ED, 0x90B21F, 0x90B931, 0x90C1C6, 0x90FD61, 0x949426, 0x94E96A, 0x94F6A3, 0x9801A7, 0x9803D8, 0x9810E8, 0x985AEB, 0x989E63,
0x98B8E3, 0x98D6BB, 0x98E0D9, 0x98F0AB, 0x98FE94, 0x9C04EB, 0x9C207B, 0x9C293F, 0x9C35EB, 0x9C4FDA, 0x9C84BF, 0x9C8BA0, 0x9CF387, 0x9CF48E, 0x9CFC01, 0xA01828, 0xA03BE3, 0xA0999B, 0xA0D795,
0xA0EDCD, 0xA43135, 0xA45E60, 0xA46706, 0xA4B197, 0xA4B805, 0xA4C361, 0xA4D18C, 0xA4D1D2, 0xA4F1E8, 0xA82066, 0xA85B78, 0xA860B6, 0xA8667F, 0xA886DD, 0xA88808, 0xA88E24, 0xA8968A, 0xA8BBCF,
0xA8FAD8, 0xAC293A, 0xAC3C0B, 0xAC61EA, 0xAC7F3E, 0xAC87A3, 0xACBC32, 0xACCF5C, 0xACFDEC, 0xB03495, 0xB0481A, 0xB065BD, 0xB0702D, 0xB09FBA, 0xB418D1, 0xB44BD2, 0xB48B19, 0xB49CDF, 0xB4F0AB,
0xB8098A, 0xB817C2, 0xB844D9, 0xB853AC, 0xB8782E, 0xB88D12, 0xB8C75D, 0xB8E856, 0xB8F6B1, 0xB8FF61, 0xBC3BAF, 0xBC4CC4, 0xBC52B7, 0xBC5436, 0xBC6778, 0xBC6C21, 0xBC926B, 0xBC9FEF, 0xBCA920,
0xBCEC5D, 0xC01ADA, 0xC06394, 0xC0847A, 0xC09F42, 0xC0CCF8, 0xC0CECD, 0xC0D012, 0xC0F2FB, 0xC42C03, 0xC4B301, 0xC81EE7, 0xC82A14, 0xC8334B, 0xC869CD, 0xC86F1D, 0xC88550, 0xC8B5B7, 0xC8BCC8,
0xC8E0EB, 0xC8F650, 0xCC088D, 0xCC08E0, 0xCC20E8, 0xCC25EF, 0xCC29F5, 0xCC4463, 0xCC785F, 0xCCC760, 0xD0034B, 0xD023DB, 0xD02598, 0xD03311, 0xD04F7E, 0xD0A637, 0xD0C5F3, 0xD0E140, 0xD4619D,
0xD49A20, 0xD4DCCD, 0xD4F46F, 0xD8004D, 0xD81D72, 0xD83062, 0xD89695, 0xD89E3F, 0xD8A25E, 0xD8BB2C, 0xD8CF9C, 0xD8D1CB, 0xDC0C5C, 0xDC2B2A, 0xDC2B61, 0xDC3714, 0xDC415F, 0xDC86D8, 0xDC9B9C,
0xDCA4CA, 0xDCA904, 0xE05F45, 0xE06678, 0xE0ACCB, 0xE0B52D, 0xE0B9BA, 0xE0C767, 0xE0C97A, 0xE0F5C6, 0xE0F847, 0xE425E7, 0xE48B7F, 0xE498D6, 0xE49A79, 0xE4C63D, 0xE4CE8F, 0xE4E4AB, 0xE8040B,
0xE80688, 0xE8802E, 0xE88D28, 0xE8B2AC, 0xEC3586, 0xEC852F, 0xECADB8, 0xF02475, 0xF07960, 0xF099BF, 0xF0B0E7, 0xF0B479, 0xF0C1F1, 0xF0CBA1, 0xF0D1A9, 0xF0DBE2, 0xF0DBF8, 0xF0DCE2, 0xF0F61C,
0xF40F24, 0xF41BA1, 0xF431C3, 0xF437B7, 0xF45C89, 0xF4F15A, 0xF4F951, 0xF80377, 0xF81EDF, 0xF82793, 0xF86214, 0xFC253F, 0xFCD848, 0xFCE998, 0xFCFC48,
]
class NetworkInfo:
def __init__(self, ifname, ip4, mac, status):
"""
Args:
ifname (str): Network interface name
ip4 (str | None): IPv4 address
mac (str | None): MAC Address
status (str | None): active or inactive
"""
self.ip4 = ip4
self.mac = mac
self.ifname = ifname
self.status = status
def __repr__(self):
cols = [
f'{self.ifname}\t',
self.mac or 'None\t\t',
f'{self.ip4}\t' if self.ip4 else 'None\t\t',
self.status or 'None'
]
return '\t'.join(cols)
def get_network_info(ifname: str = 'en0') -> NetworkInfo:
cmd = f'ifconfig {ifname}'
output = subprocess \
.check_output(cmd, shell=True) \
.decode('utf-8') \
.split('\n')
keys = ['ether', 'inet ', 'inet6 ', 'status:']
lines = [line.strip() for line in output if any(line.strip().startswith(key) for key in keys)]
if len(lines) < 2:
return None
info = {}
for line in lines:
row = line \
.replace(': ', ' ') \
.split(' ')
key = row[0]
val = row[1]
info[key] = val
mac = info.get('ether', None)
ip4 = info.get('inet', None)
status = info.get('status', None)
netinfo = NetworkInfo(ifname, ip4, mac, status)
return netinfo
def set_mac(mac: str, ifname: str = 'en0'):
try:
old_info = get_network_info(ifname)
cmd = ';'.join([
'/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z', # disasocciate from network
f'ifconfig {ifname} ether {mac}' # set new mac address
])
subprocess.check_call(cmd, shell=True)
new_info = get_network_info(ifname)
print(f'{old_info.mac} => {new_info.mac}')
except Exception as err:
raise err
def list_all_interface_info():
net_infos = []
ifnames = socket.if_nameindex()
for _, name in ifnames:
netinfo = get_network_info(name)
if netinfo is not None:
net_infos.append(netinfo)
print('Interface\tMAC Address\t\tIPv4\t\t\tStatus')
for net in net_infos:
print(net)
def unsafe_mac_rotate() -> str:
lower = 0
upper = 255
return ':'.join([
'{:02x}'.format(randint(lower, upper))
for i in range(6)
])
def mac_rotate() -> str:
lower = 0
upper = 255
prefix_idx = randint(0, len(apple_mac_address_prefixes)-1)
prefix =f'{apple_mac_address_prefixes[prefix_idx]:06x}'
suffix = f'{randint(lower, upper):02x}{randint(lower, upper):02x}{randint(lower, upper):02x}'
mac = prefix + suffix
return ':'.join([
mac[i:i+2]
for i in range(0, len(mac), 2)
])
def validate_address(mac: str):
bits = [int(bit, 16) for bit in mac.split(':')]
if len(bits) > 6:
print(f'Invlaid MAC address {mac} - address can only be 6 bits long', file=sys.stderr)
sys.exit(1)
valid = True
invalid_bit = None
for bit in bits:
if bit > 255:
valid = False
invalid_bit = bit
break
if valid == False:
print(f'Invlaid MAC address {mac} - address bit too large `:{invalid_bit:x}`', file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
parser = ArgumentParser(prog='macaddr', description='MAC address helper')
parser.add_argument('-r', '--rotate', type=bool, default=False, action=BooleanOptionalAction, help='generate new MAC address with a valid Apple prefix')
parser.add_argument('-R', '--unsafe-rotate', type=bool, default=False, action=BooleanOptionalAction, help='generate a completely random MAC address')
parser.add_argument('-l', '--list-all', type=bool, default=False, action=BooleanOptionalAction, help='show mac address of all network interfaces')
parser.add_argument('-a', '--address', type=str, default=None, help='manually set MAC address')
parser.add_argument('-i', '--interface', type=str, default='en0', help='specify which network-interface MAC address to change')
args = vars(parser.parse_args())
rotate = args['rotate']
unsafe_rotate = args['unsafe_rotate']
list_all = args['list_all']
address = args['address']
interface = args['interface']
if address is not None:
validate_address(address)
new_mac = address
set_mac(new_mac, interface)
elif rotate:
new_mac = mac_rotate()
validate_address(new_mac)
set_mac(new_mac, interface)
elif unsafe_rotate:
new_mac = unsafe_mac_rotate()
validate_address(new_mac)
set_mac(new_mac, interface)
elif list_all:
list_all_interface_info()
else:
info = get_network_info()
print(info.mac)