Giter VIP home page Giter VIP logo

babatundeonabajo / fetch-ip-address-information-for-android Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 66 KB

This is a brief script for Android programmers that enables them to fetch information surrounding an IP Address from IP2Location. An API key from IP2Location.io is needed. It was an entry to the 2022 IP2Location Geolocation Contest.

License: MIT License

Java 100.00%
android gradle groovy ip-address java xml

fetch-ip-address-information-for-android's Introduction

About Fetch IP Address for Android

This is a short - spanning only one Activity - but useful script for programmers in Android development to extract information relating to an IP address from IP2Location. This script obtains the following information from IP2Location where available:

  • IP Address
  • Country code
  • Country name
  • Region name
  • City name
  • Latitude
  • Longitude
  • Zip code
  • Time zone
  • ASN
  • AS
  • Whether or not IP address is a proxy

Note that this script can only be used for the XML option for IP2Location. It does not work for the JSON version; please consult a different script if this is your preference.

Instructions

You can copy and paste this code. You only need to edit the variable identified as APIKEY (which indicates the API key you should have obtained from IP2Location. Contact them if you would like information on how to receive this) as well as ipADDRESS (which refers to the IP Address you would like to obtain information for).

In order to see this code in action using Android Studio, copy the create a new project in Android Studio and name the project "Fetch IP Addresses Online for Android". Android Studio should then automatically create a package name called "com.example.fetchipaddressesonlineforandroid". Also select the option Empty Activity . Then copy all the information from MainActiviy.java here and paste it into the file, overwriting anything that might be present.

To test the script, a series of Toast functions are in the script. They are commented out, but you can uncomment them in MainActivity.java to see them in action. To see them in action, click "Run 'app'" and then the emulator should open up. Click on the app that has been installed and you should see the requested information appear as a series of Toast bubble messages.

Be sure to copy all the code in AndroidManifest.xml and paste it into the AndroidManifest.xml file that is automatically generated by Android Studio, overwriting anything that might be present.

Requirements

  • Android Studio, Eclipse or a similar Integrated Development Environment (IDE) that can compile and run Android software.
  • Windows, Mac or Linux
  • Internet access
  • It is not necessary to have a device such as a desktop or laptop with sufficient computing power to run an emulator unless you would like to see this code in action.

It is not necessary to have a physical Android device but you can test it on your device as well if that suits your fancy. Given the elemental nature of this script, this script should work on practically all versions of Android, despite the fact that targetSdkVersion is labelled as 33 and compileSdkVersion is 33. However, you might need to change the line import androidx.appcompat.app.AppCompatActivity; . Please consult official Android documentation surrounding this, otherwise just continue with the latest version of Android as of writing (33). Then copy and paste the code in this repository labelled "MainActivity.java". Once that is done, you must edit the constant APIKEY to include your API key and edit the constant ipADDRESS for the IP Address you want to look up. Voila! You are now able to fetch information for IP addresses on Android. This script handles all the difficult stuff in the context of Android, such as connecting to the internet as well as managing threads. You can build upon this script, for instance, saving the variable responseForCountryName into a local database.

Credits

  • Babatunde Onabajo (ChurchMapped Limited)
  • IP2Location

Disclaimer

  • "This site or product includes IP2Location LITE data available from http://www.ip2location.com." IP2Location is a registered trademark of Hexasoft Development Sdn Bhd. All other trademarks are the property of their respective owners.
  • This script is written in a personal capacity by Babatunde Onabajo. This script does not reflect the opinion(s) of any past, present or future employer. Any geographical or political categorisation associated with the response from information provided by IP2Location does not necessarily imply or reflect the personal opinion held by Babatunde Onabajo.

fetch-ip-address-information-for-android's People

Contributors

babatundeonabajo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.