Skip to main content

User Location & Connection Status

In many scenarios, we need to know the location of the customer or the current VPN location, in case the customer is currently connected to the VPN, in order to either present them in the reports or to obtain the best smart location.

This is implemented, by performing an API call to the Instance Discovery Service /conn_status endpoint. This endpoint receives the request’s IP address and will use the Maxmind Service, to lookup information about that IP , such as Country, ISP, ASN etc.

In case the user is not connected to the VPN, the result will represent information about the user’s “real” aka ISP location. If the user is connected to the VPN, the result will represent the information about the current VPN server location. The Instance Discovery Service can thus lookup the request IP and check if it’s a known VPN IP. If that' the case the returned connection status is vpn_connected=true, otherwise it will be false.

fn get_user_location(&self, mode: LocationMode) -> Result<GeoLocation>

LocationMode

danger

The real location will be cached in the SDK. In order to update the location, always call the SDK Managers networkChanged() method whenever you change the status of the VPN connection, the user switched between WiFi/Cellular or a significant location change was detected (e.g. user switched into a different network).

NameDescription
AutoThis mode will return what ever location is currently available, based on whether the user is connected to the VPN or not.
RealLocationThis mode aims to provide the actual Internet Service Provider (ISP) location of the customer. If the customer is connected to a VPN, making the real location inaccessible, the SDK will attempt to retrieve a previously cached location. In the event that no cached location is available, an exception, SdkException::RealLocationNotAvailable, will be thrown, which is encapsulated by an InstanceDiscoveryException.
VPNLocationThis mode is only available while the user is currently connected to the VPN and will return the VPN Location. If the user is not connected, the SDK will return SdkException::VPNLocationNotAvailable.The VPN location is not cached for privacy reasons.

Geolocation

NameTypeDescription
current_ipStringIP Address
iso_country_codeStringISO country code associated with the IP
regionStringRegion code associated with the IP
ispStringISP name associated with the IP
asnStringAutonomous System Number associated with the IP
latitudeFloatLatitude of the geolocation associated with that IP
longitudeFlaotLongitude of the geolocation associated with that IP
vpn_connectedBooltrue, if that IP is associated with the brand's IP pool.