24 lines
737 B
Python
24 lines
737 B
Python
import re
|
|
import random
|
|
|
|
def generate_random_ip():
|
|
return f"{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}"
|
|
|
|
def replace_ips_in_file(file_path):
|
|
with open(file_path, 'r') as file:
|
|
content = file.read()
|
|
|
|
# Regular expression to match IP addresses
|
|
ip_pattern = r'\b(?:\d{1,3}\.){3}\d{1,3}\b'
|
|
|
|
# Replace IPs with random IPs
|
|
modified_content = re.sub(ip_pattern, lambda _: generate_random_ip(), 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_ips_in_file(file_path)
|
|
print("IP addresses replaced successfully.")
|