|
1 | 1 | import xml.etree.ElementTree as ET |
2 | | -from random import randint, choice, sample |
| 2 | +from random import randint, choice, choices, sample |
3 | 3 | import datetime |
4 | 4 |
|
5 | 5 | def generate_nmap_xml(num_hosts=1000, base_subnet="172.16"): |
@@ -62,20 +62,49 @@ def generate_nmap_xml(num_hosts=1000, base_subnet="172.16"): |
62 | 62 | "afp": {"product": "Netatalk AFP", "version": "3.1.12"} |
63 | 63 | } |
64 | 64 |
|
| 65 | + # Expanded lists for generating hostnames |
| 66 | + colors = ["Red", "Blue", "Green", "Yellow", "Purple", "Orange", "Cyan", "Magenta", "Lime", "Pink"] |
| 67 | + foods = ["Apple", "Burger", "Cake", "Dumpling", "Eclair", "Pizza", "Sushi", "Taco", "Waffle", "Bagel"] |
| 68 | + cities = ["Tokyo", "Paris", "London", "NewYork", "Sydney", "Berlin", "Rome", "Madrid", "Moscow", "Beijing"] |
| 69 | + verbs = ["Jumping", "Running", "Flying", "Swimming", "Dancing", "Singing", "Playing", "Walking", "Reading", "Writing"] |
| 70 | + |
| 71 | + # Unique hostname tracker |
| 72 | + generated_hostnames = set() |
| 73 | + |
| 74 | + # Function to create unique random hostnames |
| 75 | + def generate_hostname(): |
| 76 | + while True: |
| 77 | + parts = [choice(colors), choice(foods), choice(cities), choice(verbs)] |
| 78 | + hostname = '.'.join(parts) |
| 79 | + # Ensure uniqueness by appending a number if needed |
| 80 | + if hostname not in generated_hostnames: |
| 81 | + generated_hostnames.add(hostname) |
| 82 | + return hostname |
| 83 | + else: |
| 84 | + hostname += str(randint(0, 9999)) |
| 85 | + if hostname not in generated_hostnames: |
| 86 | + generated_hostnames.add(hostname) |
| 87 | + return hostname |
| 88 | + |
65 | 89 | # Function to create a random IP address within the extended subnet range |
66 | 90 | def random_ip(base_subnet, host_number): |
67 | 91 | subnet_third_octet = host_number // 254 |
68 | 92 | host_fourth_octet = host_number % 254 + 1 |
69 | 93 | return f"{base_subnet}.{subnet_third_octet}.{host_fourth_octet}" |
70 | 94 |
|
71 | | - # Generating hosts with updated IP address method |
| 95 | + # Generating hosts with updated IP address and hostname method |
72 | 96 | for i in range(num_hosts): |
73 | 97 | host_os = choice(list(os_services.keys())) |
74 | 98 |
|
75 | 99 | host = ET.Element("host") |
76 | 100 | ET.SubElement(host, "status", {"state": "up", "reason": "arp-response", "reason_ttl": "0"}) |
77 | 101 | ET.SubElement(host, "address", {"addr": random_ip(base_subnet, i), "addrtype": "ipv4"}) |
78 | | - ET.SubElement(host, "hostnames") |
| 102 | + |
| 103 | + # Hostnames |
| 104 | + hostnames = ET.SubElement(host, "hostnames") |
| 105 | + num_hostnames = randint(1, 3) # Random number of hostnames per host |
| 106 | + for _ in range(num_hostnames): |
| 107 | + ET.SubElement(hostnames, "hostname", {"name": generate_hostname(), "type": "user"}) |
79 | 108 |
|
80 | 109 | # Ports |
81 | 110 | ports = ET.SubElement(host, "ports") |
@@ -135,7 +164,7 @@ def random_ip(base_subnet, host_number): |
135 | 164 | xml_str = xml_header + '\n' + ET.tostring(nmaprun, encoding='unicode', method='xml') |
136 | 165 | return xml_str |
137 | 166 |
|
138 | | -def save_nmap_xml(filename, num_hosts=1000, base_subnet="172.16"): |
| 167 | +def save_nmap_xml(filename, num_hosts=200, base_subnet="172.16"): |
139 | 168 | # Generate the XML content |
140 | 169 | xml_content = generate_nmap_xml(num_hosts, base_subnet) |
141 | 170 |
|
|
0 commit comments