| 62 | [("Network", "Netmask", "Gateway", "Iface", "Output IP", "Metric")]) # noqa: E501 |
| 63 | |
| 64 | def make_route(self, |
| 65 | host=None, # type: Optional[str] |
| 66 | net=None, # type: Optional[str] |
| 67 | gw=None, # type: Optional[str] |
| 68 | dev=None, # type: Optional[str] |
| 69 | metric=1, # type: int |
| 70 | ): |
| 71 | # type: (...) -> Tuple[int, int, str, str, str, int] |
| 72 | if host is not None: |
| 73 | thenet, msk = host, 32 |
| 74 | elif net is not None: |
| 75 | thenet, msk_b = net.split("/") |
| 76 | msk = int(msk_b) |
| 77 | else: |
| 78 | raise Scapy_Exception("make_route: Incorrect parameters. You should specify a host or a net") # noqa: E501 |
| 79 | if gw is None: |
| 80 | gw = "0.0.0.0" |
| 81 | if dev is None: |
| 82 | if gw: |
| 83 | nhop = gw |
| 84 | else: |
| 85 | nhop = thenet |
| 86 | dev, ifaddr, _ = self.route(nhop) |
| 87 | else: |
| 88 | ifaddr = "0.0.0.0" # acts as a 'via' in `ip addr add` |
| 89 | return (atol(thenet), itom(msk), gw, dev, ifaddr, metric) |
| 90 | |
| 91 | def add(self, *args, **kargs): |
| 92 | # type: (*Any, **Any) -> None |