Added features
@ -1,63 +0,0 @@
|
||||
package com.paulbsd.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by paul on 07/06/17.
|
||||
*/
|
||||
public class getIpInfo {
|
||||
|
||||
public String url;
|
||||
public String ip;
|
||||
public String hostname;
|
||||
public String city;
|
||||
public String org;
|
||||
public String resp;
|
||||
|
||||
public getIpInfo(String url) throws Exception
|
||||
{
|
||||
this.url = url;
|
||||
this.resp = getHTML(this.url);
|
||||
JSONObject reader = new JSONObject(resp);
|
||||
this.ip = reader.getString("ip");
|
||||
this.hostname = reader.getString("hostname");
|
||||
this.city = reader.getString("city");
|
||||
this.org = reader.getString("org");
|
||||
}
|
||||
|
||||
public static String getHTML(String urlToRead) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
URL url = new URL(urlToRead);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
rd.close();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getIp()
|
||||
{
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public String getHostname()
|
||||
{
|
||||
return this.hostname;
|
||||
}
|
||||
|
||||
public String getCity()
|
||||
{
|
||||
return this.city;
|
||||
}
|
||||
|
||||
public String getOrg()
|
||||
{
|
||||
return this.org;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/activity_main"
|
||||
tools:context="com.paulbsd.app.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:text="@string/public_ip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20pt"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:id="@+id/Title" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/refresh"
|
||||
android:id="@+id/but"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/PublicIP"
|
||||
android:textSize="10pt"
|
||||
android:layout_marginTop="27dp"
|
||||
android:layout_below="@+id/Title"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/Hostname"
|
||||
android:textSize="8pt"
|
||||
android:layout_below="@+id/PublicIP"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="28dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/City"
|
||||
android:textSize="10pt"
|
||||
android:layout_below="@+id/Hostname"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="18dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/Org"
|
||||
android:textSize="10pt"
|
||||
android:layout_marginTop="43dp"
|
||||
android:layout_below="@+id/City"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,6 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">PaulBSD MyIP</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
<string name="public_ip">Public IP</string>
|
||||
</resources>
|
@ -1,4 +1,4 @@
|
||||
package com.paulbsd.app;
|
||||
package com.paulbsd.myip;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.paulbsd.app" >
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.paulbsd.myip" >
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
@ -1,4 +1,4 @@
|
||||
package com.paulbsd.app;
|
||||
package com.paulbsd.myip;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.StrictMode;
|
||||
@ -17,10 +17,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT > 9) {
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
}
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
@ -32,22 +30,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
Button but = (Button) findViewById(R.id.but);
|
||||
|
||||
this.updateIpInfo(publicip,hostname,city,org);
|
||||
|
||||
but.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateIpInfo(publicip,hostname,city,org);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateIpInfo(TextView publicip, TextView hostname, TextView city, TextView org) {
|
||||
try {
|
||||
getIpInfo ipinfo = new getIpInfo("http://ipinfo.io/json");
|
||||
getIpInfo ipinfo = new getIpInfo("https://ipinfo.io/json");
|
||||
publicip.setText(ipinfo.getIp());
|
||||
hostname.setText(ipinfo.getHostname());
|
||||
city.setText(ipinfo.getCity());
|
||||
org.setText(ipinfo.getOrg());
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
79
paulbsd-myip/src/main/java/com/paulbsd/myip/getIpInfo.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.paulbsd.myip;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class getIpInfo {
|
||||
|
||||
// Main URL
|
||||
private String url;
|
||||
|
||||
// IP attributes
|
||||
private String ip = "undef";
|
||||
private String hostname = "undef";
|
||||
private String city = "undef";
|
||||
private String org = "undef";
|
||||
|
||||
// Response
|
||||
private String resp;
|
||||
|
||||
getIpInfo(String url) throws Exception
|
||||
{
|
||||
this.url = url;
|
||||
|
||||
System.out.println("Initiating connection to " + this.url);
|
||||
|
||||
this.resp = getHTML(this.url);
|
||||
JSONObject reader = new JSONObject(resp);
|
||||
|
||||
System.out.println("Terminating connection to " + this.url);
|
||||
|
||||
try {
|
||||
this.ip = reader.getString("ip");
|
||||
this.hostname = reader.getString("hostname");
|
||||
this.city = reader.getString("city");
|
||||
this.org = reader.getString("org");
|
||||
}
|
||||
catch (JSONException jse)
|
||||
{
|
||||
System.out.println(jse);
|
||||
}
|
||||
}
|
||||
|
||||
static String getHTML(String urlToRead) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
URL url = new URL(urlToRead);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
rd.close();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
String getIp()
|
||||
{
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
String getHostname()
|
||||
{
|
||||
return this.hostname;
|
||||
}
|
||||
|
||||
String getCity()
|
||||
{
|
||||
return this.city;
|
||||
}
|
||||
|
||||
String getOrg()
|
||||
{
|
||||
return this.org;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.paulbsd.app.MainActivity">
|
||||
tools:context="com.paulbsd.myip.MainActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_height="wrap_content"
|
147
paulbsd-myip/src/main/res/layout/content_main.xml
Normal file
@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="com.paulbsd.myip.MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/notification_large_icon_height"
|
||||
android:layout_marginTop="@dimen/notification_large_icon_height">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/ip"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="14pt"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/PublicIP"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="14pt" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/host"
|
||||
android:textSize="14pt"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Hostname"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="10pt" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/city"
|
||||
android:textSize="14pt"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/City"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="10pt" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/provider"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="14pt"
|
||||
android:textStyle="bold" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Org"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="textStart"
|
||||
android:textSize="10pt" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="@string/app_header"
|
||||
android:textSize="16pt" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/but"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="@string/button_refresh" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.paulbsd.app.MainActivity" >
|
||||
tools:context="com.paulbsd.myip.MainActivity" >
|
||||
<item android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
android:orderInCategory="100"
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
11
paulbsd-myip/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
<string name="app_name">PaulBSD ShowMyIP</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="button_refresh">Refresh</string>
|
||||
<string name="app_header">Public IP</string>
|
||||
<string name="ip_address_resolution_service_url">https://ipinfo.io/json</string>
|
||||
<string name="ip">IP</string>
|
||||
<string name="host">Host</string>
|
||||
<string name="city">City</string>
|
||||
<string name="provider">Provider</string>
|
||||
</resources>
|
@ -1,4 +1,4 @@
|
||||
package com.paulbsd.app;
|
||||
package com.paulbsd.myip;
|
||||
|
||||
import org.junit.Test;
|
||||
|