Send ARP who-has requests to determine which hosts are up:: arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None Set cache=True if you want arping to modify internal ARP-Cache
(net: str,
timeout: int = 2,
cache: int = 0,
verbose: Optional[int] = None,
threaded: bool = True,
**kargs: Any,
)
| 1048 | |
| 1049 | @conf.commands.register |
| 1050 | def arping(net: str, |
| 1051 | timeout: int = 2, |
| 1052 | cache: int = 0, |
| 1053 | verbose: Optional[int] = None, |
| 1054 | threaded: bool = True, |
| 1055 | **kargs: Any, |
| 1056 | ) -> Tuple[ARPingResult, PacketList]: |
| 1057 | """ |
| 1058 | Send ARP who-has requests to determine which hosts are up:: |
| 1059 | |
| 1060 | arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None |
| 1061 | |
| 1062 | Set cache=True if you want arping to modify internal ARP-Cache |
| 1063 | """ |
| 1064 | if verbose is None: |
| 1065 | verbose = conf.verb |
| 1066 | |
| 1067 | hwaddr = None |
| 1068 | if "iface" in kargs: |
| 1069 | hwaddr = get_if_hwaddr(kargs["iface"]) |
| 1070 | if isinstance(net, list): |
| 1071 | hint = net[0] |
| 1072 | else: |
| 1073 | hint = str(net) |
| 1074 | psrc = conf.route.route( |
| 1075 | hint, |
| 1076 | dev=kargs.get("iface", None), |
| 1077 | verbose=False, |
| 1078 | _internal=True, # Do not follow default routes. |
| 1079 | )[1] |
| 1080 | if psrc == "0.0.0.0" and "iface" not in kargs: |
| 1081 | warning( |
| 1082 | "Could not find the interface for destination %s based on the routes. " |
| 1083 | "Using conf.iface. Please provide an 'iface' !" % hint |
| 1084 | ) |
| 1085 | |
| 1086 | ans, unans = srp( |
| 1087 | Ether(dst="ff:ff:ff:ff:ff:ff", src=hwaddr) / ARP( |
| 1088 | pdst=net, |
| 1089 | psrc=psrc, |
| 1090 | hwsrc=hwaddr |
| 1091 | ), |
| 1092 | verbose=verbose, |
| 1093 | filter="arp and arp[7] = 2", |
| 1094 | timeout=timeout, |
| 1095 | threaded=threaded, |
| 1096 | iface_hint=hint, |
| 1097 | **kargs, |
| 1098 | ) |
| 1099 | ans = ARPingResult(ans.res) |
| 1100 | |
| 1101 | if cache and ans is not None: |
| 1102 | for pair in ans: |
| 1103 | _arp_cache[pair[1].psrc] = pair[1].hwsrc |
| 1104 | if ans is not None and verbose: |
| 1105 | ans.show() |
| 1106 | return ans, unans |
| 1107 |
no test coverage detected