Home | Trees | Indices | Help |
---|
|
object --+ | CarrierApi
The main class for the Carrier Detection API. Used to load the data file and perform lookups using IPv4 addresses.
Please note that is advisable to load only a single instance of this class to avoid multiple loadings of the data file.
Example usage:
>>> # Import the DeviceAtlas CarrierApi module. >>> from mobi.mtld.da.carrier.carrier_api import CarrierApi >>> >>> ip = '62.40.34.220' >>> carrier_api = CarrierApi() >>> carrier_api.load_data_from_file("/path/to/sample.dat") >>> >>> # Get all properties >>> properties = carrier_api.get_properties(ip) >>> >>> # Use the properties >>> if 'networkOperator' in properties: >>> operator_name = str(properties['networkOperator']) >>> print("networkOperator: " + operator_name) >>> >>> # Get a single property >>> mcc_property = carrier_api.get_property(ip, 'mcc') >>> >>> if mcc_property is not None: >>> print("MCC: " + str(mcc_property))
Please see the code in the Examples directory for additional samples.
Copyright: Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved.
Author: DeviceAtlas Limited
Instance Methods | |||
|
|||
|
|||
|
|||
|
|||
Properties, None |
|
||
Property, None |
|
||
list |
|
||
str |
|
||
|
|||
bool |
|
||
|
|||
Inherited from |
Properties | |
Inherited from |
Method Details |
Load the data file from the provided path. The data file is reloaded every time this method is called.
|
Returns the data file copyright text.
|
Returns the data file creation date in ISO8601 format.
|
Returns the version of the data file.
|
Get the Carrier properties for a given IP address or for a given dictionary of HTTP headers. In case a dictionary is passed, the API will choose the most appropriate IP to use by checking the following headers: - X-Forwarded-For - Client-Ip - X-Client-Ip - rlnClientIpAddr - Proxy-Client-Ip - Wl-Proxy-Client-Ip - X-Forwarded - Forwarded-For - Forwarded
|
Try to obtain a specific property for a given IP address.
Note: If multiple properties are needed for the same IP, it is more efficient to call get_properties() once rather than repeated call to get_property(). |
A list of all the property names. The list contains PropertyName objects that each have a string name and an associated data type.
|
Get the most suitable IP address from the given keyVals dictionary of HTTP headers.
|
Checks if the given propertyName is not None and exists in the data file. Calls to this methods must ensure that the data object is already loaded.
|
An IP address is considered public if it is not in any of the following ranges:
|
Extracts and cleans an IP address from the headerValue. Some headers such as "X-Forwarded-For" can contain multiple IP addresses such as: clientIP, proxy1, proxy2... This method splits up the headerValue and takes the most appropriate value as the IP.
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Dec 4 11:30:34 2019 | http://epydoc.sourceforge.net |