When examinging reverse DNS records, Marinus can match based on the IP address range owned by the organization. This will an IPv4 CIDR to the list of the organizations known ranges. This information is stored in the ip_zones collection.
(mongo_collection, cidr)
| 361 | |
| 362 | |
| 363 | def create_IPv4_zone(mongo_collection, cidr): |
| 364 | """ |
| 365 | When examinging reverse DNS records, Marinus can match based on the IP address range owned by the organization. |
| 366 | This will an IPv4 CIDR to the list of the organizations known ranges. |
| 367 | This information is stored in the ip_zones collection. |
| 368 | """ |
| 369 | ipv4_zone_collection = mongo_collection.get_ipzone_connection() |
| 370 | now = datetime.now() |
| 371 | |
| 372 | double_check = ipv4_zone_collection.count_documents({"zone": cidr}) |
| 373 | if double_check != 0: |
| 374 | print("CIDR value: " + cidr + " already exists!") |
| 375 | return |
| 376 | |
| 377 | try: |
| 378 | foo = ipaddress.ip_network(cidr) |
| 379 | except: |
| 380 | print("Error: Not a valid CIDR value") |
| 381 | return |
| 382 | |
| 383 | if type(foo) is not ipaddress.IPv4Network: |
| 384 | print("Not an IPv4 Address") |
| 385 | return |
| 386 | |
| 387 | new_entry = {} |
| 388 | new_entry["status"] = "unconfirmed" |
| 389 | new_entry["source"] = "manual" |
| 390 | new_entry["updated"] = now |
| 391 | new_entry["created"] = now |
| 392 | new_entry["notes"] = [] |
| 393 | new_entry["zone"] = cidr |
| 394 | |
| 395 | print("Inserting IPv4 zone: " + cidr) |
| 396 | ipv4_zone_collection.insert_one(new_entry) |
| 397 | |
| 398 | |
| 399 | def create_IPv6_zone(mongo_collection, cidr): |
no test coverage detected