MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / scan_network

Function scan_network

Scripts/Developer Base/Devices Finder.py:1043–1120  ·  view source on GitHub ↗
(subnet, ports, verbose=False, exclude_self=False, self_ip=None,
                 timing="T4", exclude_targets=None, max_hostgroup=None,
                 deep_scan=False)

Source from the content-addressed store, hash-verified

1041# MAIN SCAN LOGIC
1042# ─────────────────────────────────────────────
1043def scan_network(subnet, ports, verbose=False, exclude_self=False, self_ip=None,
1044 timing="T4", exclude_targets=None, max_hostgroup=None,
1045 deep_scan=False):
1046 divider()
1047 info(f"Target subnet : {ccolor(WHITE, subnet)}")
1048 info(f"Ports : {ccolor(WHITE, ', '.join(map(str, ports)))}")
1049 if exclude_targets:
1050 info(f"Exclude : {ccolor(WHITE, exclude_targets)}")
1051 if deep_scan:
1052 info(ccolor(WHITE, "Deep scan enabled (mDNS / UPnP / SNMP / NetBIOS)"))
1053 divider()
1054 print()
1055
1056 start = datetime.datetime.now()
1057
1058 records = discover_hosts(
1059 subnet=subnet,
1060 local_ip=self_ip,
1061 exclude_self=exclude_self,
1062 exclude_targets=exclude_targets,
1063 timing=timing,
1064 )
1065
1066 if not records:
1067 duration = (datetime.datetime.now() - start).total_seconds()
1068 return [], duration
1069
1070 success(f"Discovered {len(records)} live or recently seen device(s)")
1071 print()
1072
1073 service_data = scan_services(
1074 host_ips=list(records.keys()),
1075 ports=ports,
1076 timing=timing,
1077 verbose=verbose,
1078 max_hostgroup=max_hostgroup,
1079 )
1080
1081 results = []
1082 for ip, record in records.items():
1083 host_service = service_data.get(ip, {})
1084 if host_service.get("mac") and not record.get("mac"):
1085 record["mac"] = normalize_mac(host_service.get("mac", ""))
1086 record["vendor"] = host_service.get("vendor") or record.get("vendor") or lookup_mac_vendor(record.get("mac", ""))
1087 record["open_ports"] = sorted(host_service.get("ports", []))
1088 record["service_info"] = host_service.get("service_info", "")
1089 record["extra_info"] = enrich_device(ip, deep_scan=deep_scan)
1090 record["device_name"] = extract_device_name(
1091 record.get("service_info", ""),
1092 vendor=record.get("vendor", ""),
1093 extra_info=record.get("extra_info", {}),
1094 )
1095 device_type, type_confidence, type_reasons = classify_device_type(
1096 ip=ip,
1097 open_ports=record.get("open_ports", []),
1098 service_info=record.get("service_info", ""),
1099 device_name=record.get("device_name", ""),
1100 vendor=record.get("vendor", ""),

Callers 1

mainFunction · 0.70

Calls 14

printFunction · 0.85
dividerFunction · 0.70
infoFunction · 0.70
ccolorFunction · 0.70
discover_hostsFunction · 0.70
successFunction · 0.70
scan_servicesFunction · 0.70
normalize_macFunction · 0.70
lookup_mac_vendorFunction · 0.70
enrich_deviceFunction · 0.70
extract_device_nameFunction · 0.70
classify_device_typeFunction · 0.70

Tested by

no test coverage detected