Special dictionnary class for storing and accessing host scan result
| 964 | |
| 965 | |
| 966 | class PortScannerHostDict(dict): |
| 967 | """ |
| 968 | Special dictionnary class for storing and accessing host scan result |
| 969 | |
| 970 | """ |
| 971 | |
| 972 | def hostnames(self): |
| 973 | """ |
| 974 | :returns: list of hostnames |
| 975 | |
| 976 | """ |
| 977 | return self["hostnames"] |
| 978 | |
| 979 | def hostname(self): |
| 980 | """ |
| 981 | For compatibility purpose... |
| 982 | :returns: try to return the user record or the first hostname of the list hostnames |
| 983 | |
| 984 | """ |
| 985 | hostname = "" |
| 986 | for h in self["hostnames"]: |
| 987 | if h["type"] == "user": |
| 988 | return h["name"] |
| 989 | else: |
| 990 | if len(self["hostnames"]) > 0 and "name" in self["hostnames"][0]: |
| 991 | return self["hostnames"][0]["name"] |
| 992 | else: |
| 993 | return "" |
| 994 | |
| 995 | return hostname |
| 996 | |
| 997 | def state(self): |
| 998 | """ |
| 999 | :returns: host state |
| 1000 | |
| 1001 | """ |
| 1002 | return self["status"]["state"] |
| 1003 | |
| 1004 | def uptime(self): |
| 1005 | """ |
| 1006 | :returns: host state |
| 1007 | |
| 1008 | """ |
| 1009 | return self["uptime"] |
| 1010 | |
| 1011 | def all_protocols(self): |
| 1012 | """ |
| 1013 | :returns: a list of all scanned protocols |
| 1014 | |
| 1015 | """ |
| 1016 | |
| 1017 | def _proto_filter(x): |
| 1018 | return x in ["ip", "tcp", "udp", "sctp"] |
| 1019 | |
| 1020 | lp = list(filter(_proto_filter, list(self.keys()))) |
| 1021 | lp.sort() |
| 1022 | return lp |
| 1023 |
no outgoing calls
no test coverage detected