Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.enzacode.enza.utils;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import com.google.gson.JsonObject;
- import com.google.gson.JsonParser;
- public class HostAPI {
- public String server = "";
- public JsonObject object;
- public HostAPI(String ip) {
- this.server = "http://ip-api.com/json/"+ip+"?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,currency,isp,org,as,asname,reverse,mobile,proxy,query";
- object = new JsonParser().parse(websitedata(server)).getAsJsonObject();
- }
- public String getAS() {
- return getObjectString("as");
- }
- public String getASNAME() {
- return getObjectString("asname");
- }
- public String getCITY() {
- return getObjectString("city");
- }
- public String getCONTIDENT() {
- return getObjectString("continent");
- }
- public String getCONTIDENTCODE() {
- return getObjectString("continentCode");
- }
- public String getCOUNTRY() {
- return getObjectString("country");
- }
- public String getCOUNTRYCODE() {
- return getObjectString("countryCode");
- }
- public String getObjectString(String obj) {
- try {
- return object.get(obj).getAsString();
- } catch (Exception e) {
- return "Unknown";
- }
- }
- public String getDISTRICT() {
- return getObjectString("district");
- }
- public String getISP() {
- return getObjectString("isp");
- }
- public String getORG() {
- return getObjectString("org");
- }
- public String getQUERY() {
- return getObjectString("query");
- }
- public String getREGIONNAME() {
- return getObjectString("regionName");
- }
- public String getREVERSE() {
- return getObjectString("reverse");
- }
- public String getTIMEZONE() {
- return getObjectString("timezone");
- }
- public boolean isRight(String obj) {
- if (!obj.isEmpty() && !obj.contains("Unknown")) {
- return true;
- } else {
- return false;
- }
- }
- public String websitedata(String website) {
- try {
- StringBuilder stringBuilder = new StringBuilder("");
- URL url = new URL(website);
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
- String line;
- while ((line = bufferedReader.readLine()) != null) {
- stringBuilder.append(line);
- }
- bufferedReader.close();
- return stringBuilder.toString();
- } catch (Exception e) {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement