`location-query search-as STRING`
`location-query list-networks-by-as ASN`
`location-query list-networks-by-cc COUNTRY_CODE`
+`location-query list-networks-by-flags [--anonymous-proxy|--satellite-provider|--anycast]`
== DESCRIPTION
The `location-query` retrieves information from the location database.
+
See above for usage of the '--output-format' parameter.
+'list-networks-by-flags [--output-format FORMAT] [--anonymous-proxy|--satellite-provider|--anycast]'::
+ Lists all networks that have a certain flag.
+ +
+ See above for usage of the '--output-format' parameter.
+
'--help'::
Shows a short help text on using this program.
}
static PyObject* Database_search_networks(DatabaseObject* self, PyObject* args, PyObject* kwargs) {
- char* kwlist[] = { "country_code", "asn", NULL };
+ char* kwlist[] = { "country_code", "asn", "flags", NULL };
const char* country_code = NULL;
unsigned int asn = 0;
+ int flags = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &country_code, &asn))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|sii", kwlist, &country_code, &asn, &flags))
return NULL;
struct loc_database_enumerator* enumerator;
}
}
+ // Set the flags we are searching for
+ if (flags) {
+ r = loc_database_enumerator_set_flag(enumerator, flags);
+
+ if (r) {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return NULL;
+ }
+ }
+
PyObject* obj = new_database_enumerator(&DatabaseEnumeratorType, enumerator);
loc_database_enumerator_unref(enumerator);
choices=self.output_formats.keys(), default="list")
list_networks_by_cc.set_defaults(func=self.handle_list_networks_by_cc)
+ # List all networks with flags
+ list_networks_by_flags = subparsers.add_parser("list-networks-by-flags",
+ help=_("Lists all networks with flags"),
+ )
+ list_networks_by_flags.add_argument("--anonymous-proxy",
+ action="store_true", help=_("Anonymous Proxies"),
+ )
+ list_networks_by_flags.add_argument("--satellite-provider",
+ action="store_true", help=_("Satellite Providers"),
+ )
+ list_networks_by_flags.add_argument("--anycast",
+ action="store_true", help=_("Anycasts"),
+ )
+ list_networks_by_flags.add_argument("--output-format",
+ choices=self.output_formats.keys(), default="list")
+ list_networks_by_flags.set_defaults(func=self.handle_list_networks_by_flags)
+
args = parser.parse_args()
# Print usage if no action was given
for n in db.search_networks(country_code=country_code):
f.network(n)
+ def handle_list_networks_by_flags(self, db, ns):
+ flags = 0
+
+ if ns.anonymous_proxy:
+ flags |= location.NETWORK_FLAG_ANONYMOUS_PROXY
+
+ if ns.satellite_provider:
+ flags |= location.NETWORK_FLAG_SATELLITE_PROVIDER
+
+ if ns.anycast:
+ flags |= location.NETWORK_FLAG_ANYCAST
+
+ with self.__get_output_formatter(ns) as f:
+ for n in db.search_networks(flags=flags):
+ f.network(n)
+
def main():
# Run the command line interface