25 lines
753 B
Python
25 lines
753 B
Python
|
import re
|
||
|
import random
|
||
|
|
||
|
def generate_random_mac():
|
||
|
# Generate a random MAC address
|
||
|
return ':'.join(f"{random.randint(0, 255):02x}" for _ in range(6))
|
||
|
|
||
|
def replace_macs_in_file(file_path):
|
||
|
with open(file_path, 'r') as file:
|
||
|
content = file.read()
|
||
|
|
||
|
# Regular expression to match MAC addresses
|
||
|
mac_pattern = r'\b(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}\b'
|
||
|
|
||
|
# Replace MACs with random MACs
|
||
|
modified_content = re.sub(mac_pattern, lambda _: generate_random_mac(), content)
|
||
|
|
||
|
with open(file_path, 'w') as file:
|
||
|
file.write(modified_content)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
file_path = 'dhcpcopy.log' # Change to your file path
|
||
|
replace_macs_in_file(file_path)
|
||
|
print("MAC addresses replaced successfully.")
|