MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / do_lldp

Function do_lldp

network_diagnostics.py:243–273  ·  view source on GitHub ↗

Return discovered switch neighbors via lldpctl. lldpd (configured with -c -e -f -s) also decodes CDPv1/v2 (Cisco), EDP (Extreme), FDP (Foundry) and SONMP (Nortel) in addition to LLDP. VLAN id/name are included when the neighbor advertises them.

()

Source from the content-addressed store, hash-verified

241 resolved_from, ip = ip, resolved
242 except (OSError, socket.gaierror):
243 return {'success': False, 'error': f'Not a valid IP or resolvable host: {target}'}
244 try:
245 rec = ip_intel.lookup(ip, allow_network=not offline)
246 except Exception as exc:
247 return {'success': False, 'error': f'lookup failed: {exc}'}
248 rec['success'] = True
249 rec['report'] = ip_intel.report(rec)
250 if resolved_from:
251 rec['resolved_from'] = resolved_from
252 return rec
253
254
255def _probe_egress(iface, timeout=4.0):
256 """Can `iface` actually reach the internet? True / False / None (unknown).
257
258 Binds the probe socket to the *device* (SO_BINDTODEVICE) and TCP-connects to
259 a public endpoint, so the answer reflects that NIC and nothing else. This is
260 the only trustworthy signal we have:
261 - a default route only says a gateway is configured, not that it works;
262 - source-address binding proves nothing at all — a probe bound to docker0's
263 address reaches the internet fine, because the packet just leaves via the
264 default-route interface wearing that address.
265 Returns None when the bind is not permitted (needs CAP_NET_RAW), so callers
266 can proceed rather than block on a check they could not run."""
267 unknown = False
268 for dst in (('1.1.1.1', 443), ('8.8.8.8', 443)):
269 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
270 try:
271 s.settimeout(timeout)
272 s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, iface.encode() + b'\0')
273 s.connect(dst)
274 return True
275 except PermissionError:
276 unknown = True

Callers 1

net_lldpFunction · 0.85

Calls 6

_haveFunction · 0.85
_runFunction · 0.85
_parse_lldp_ifaceFunction · 0.85
appendMethod · 0.80
getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected