diff --git a/.gitignore b/.gitignore index 796b96d..603b140 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store /build +/captures +.externalNativeBuild +.cxx diff --git a/.gradle/6.1.1/fileChanges/last-build.bin b/.gradle/6.1.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/6.1.1/fileChanges/last-build.bin differ diff --git a/.gradle/6.1.1/fileHashes/fileHashes.lock b/.gradle/6.1.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..738d430 Binary files /dev/null and b/.gradle/6.1.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/6.1.1/gc.properties b/.gradle/6.1.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore index 0e40fe8..5c98b42 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,2 @@ - # Default ignored files /workspace.xml \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ac6b0ae --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..0232076 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.paulbsd.myip" + minSdkVersion 19 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' + implementation 'com.google.android.material:material:1.0.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..2c2d434 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + >>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/AndroidManifest.xml + android:label="@string/app_name" + android:theme="@style/AppTheme.NoActionBar"> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/paulbsd/myip/MainActivity.java b/app/src/main/java/com/paulbsd/myip/MainActivity.java new file mode 100644 index 0000000..d94879a --- /dev/null +++ b/app/src/main/java/com/paulbsd/myip/MainActivity.java @@ -0,0 +1,98 @@ +package com.paulbsd; + +import android.os.Build; +import android.os.Bundle; +import android.os.StrictMode; +<<<<<<< HEAD:paulbsdmyip/src/com/paulbsd/main.java +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +======= +import android.widget.Toolbar; +>>>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/java/com/paulbsd/myip/MainActivity.java +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; + +public class MainActivity extends AppCompatActivity { + + String url = "https://ipinfo.io/json"; + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + final TextView public_ip = (TextView) findViewById(R.id.PublicIP); + final TextView hostname = (TextView) findViewById(R.id.Hostname); + final TextView city = (TextView) findViewById(R.id.City); + final TextView org = (TextView) findViewById(R.id.Org); + + Button but = (Button) findViewById(R.id.but); + +<<<<<<< HEAD:paulbsdmyip/src/com/paulbsd/main.java + this.updateIpInfo(publicip, hostname, city, org); +======= + this.updateIpInfo(public_ip,hostname,city,org); +>>>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/java/com/paulbsd/myip/MainActivity.java + + but.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { +<<<<<<< HEAD:paulbsdmyip/src/com/paulbsd/main.java + updateIpInfo(publicip, hostname, city, org); +======= + updateIpInfo(public_ip,hostname,city,org); +>>>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/java/com/paulbsd/myip/MainActivity.java + } + }); + } + + private void setSupportActionBar(Toolbar toolbar) { + } + + public void updateIpInfo(TextView public_ip, TextView hostname, TextView city, TextView org) { + try { + getIpInfo ipinfo = new getIpInfo(this.url); + public_ip.setText(ipinfo.getIp()); + hostname.setText(ipinfo.getHostname()); + city.setText(ipinfo.getCity()); + org.setText(ipinfo.getOrg()); + } catch (Exception e) { + + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/paulbsd/myip/getIpInfo.java b/app/src/main/java/com/paulbsd/myip/getIpInfo.java new file mode 100644 index 0000000..b2d92fa --- /dev/null +++ b/app/src/main/java/com/paulbsd/myip/getIpInfo.java @@ -0,0 +1,94 @@ +package com.paulbsd; + +import org.json.JSONException; +import org.json.JSONObject; + +public class getIpInfo { + + // Main URL + String url; + + // IP attributes + private String ip = "undef"; + private String hostname = "undef"; + private String city = "undef"; + private String org = "undef"; + + // Response + String resp; + +<<<<<<< HEAD:paulbsdmyip/src/com/paulbsd/getIpInfo.java + getIpInfo(String url) throws Exception { +======= + public getIpInfo(String url) throws Exception + { +>>>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/java/com/paulbsd/myip/getIpInfo.java + 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); + } + } + + 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(); + } + +<<<<<<< HEAD:paulbsdmyip/src/com/paulbsd/getIpInfo.java + String getIp() { + return this.ip; + } + + String getHostname() { + return this.hostname; + } + + String getCity() { + return this.city; + } + + String getOrg() { +======= + public String getIp() + { + return this.ip; + } + + public String getHostname() + { + return this.hostname; + } + + public String getCity() + { + return this.city; + } + + public String getOrg() + { +>>>>>>> 64e9f08dbcd4adcd0791cbe73337bd2b3822ecce:app/src/main/java/com/paulbsd/myip/getIpInfo.java + return this.org; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..0d17026 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..2146ea5 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +