Show organization for host

This commit is contained in:
M66B
2019-03-09 15:46:49 +00:00
parent 5aa35797f1
commit 0f294e4f4b
5 changed files with 72 additions and 3 deletions

View File

@@ -73,6 +73,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -93,6 +95,7 @@ import javax.mail.MessageRemovedException;
import javax.mail.MessagingException;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.net.ssl.HttpsURLConnection;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
@@ -1000,4 +1003,19 @@ public class Helper {
static String sanitizeFilename(String name) {
return (name == null ? null : name.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
}
static String getOrganization(String host) throws IOException {
InetAddress address = InetAddress.getByName(host);
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(15 * 1000);
connection.connect();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String organization = reader.readLine();
if ("undefined".equals(organization))
organization = null;
return organization;
}
}
}