You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: nxc/database.py
+20-3Lines changed: 20 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -112,15 +112,32 @@ def initialize_db():
112
112
init_protocol_dbs("default")
113
113
114
114
defformat_host_query(q, filter_term, HostsTable):
115
-
# one annoying thing is that if you search for an ip such as '10.10.10.5', it will return 10.10.10.5 and 10.10.10.52, so we have to check if its an ip address first
115
+
"""One annoying thing is that if you search for an ip such as '10.10.10.5',
116
+
it will return 10.10.10.5 and 10.10.10.52, so we have to check if its an ip address first
117
+
"""
118
+
# the FTP and SSH protocols call the column host instead of IP
119
+
# TODO: normalize these column names
120
+
ifhasattr(HostsTable.c, "ip"):
121
+
ip_column=HostsTable.c.ip
122
+
nxc_logger.debug("Using 'ip' column for filtering")
123
+
elifhasattr(HostsTable.c, "host"):
124
+
ip_column=HostsTable.c.host
125
+
nxc_logger.debug("Using 'host' column for filtering")
126
+
else:
127
+
nxc_logger.debug("Neither 'ip' nor 'host' columns found in the table")
128
+
returnq
129
+
130
+
# first we check if its an ip address
116
131
try:
117
132
ipaddress.ip_address(filter_term)
118
133
nxc_logger.debug(f"filter_term is an IP address: {filter_term}")
119
-
q=q.filter(HostsTable.c.ip==filter_term)
134
+
q=q.filter(ip_column==filter_term)
120
135
exceptValueError:
121
136
nxc_logger.debug(f"filter_term is not an IP address: {filter_term}")
0 commit comments