From 4fb054e8dd421f9236b799143080924b5df7193a Mon Sep 17 00:00:00 2001 From: lionche <35259787+lionche@users.noreply.github.com> Date: Sat, 21 Nov 2020 15:06:58 +0800 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/compiler.xml | 6 + .idea/gradle.xml | 22 +++ .idea/jarRepositories.xml | 25 +++ .idea/misc.xml | 9 + app/.gitignore | 1 + app/build.gradle | 42 +++++ app/proguard-rules.pro | 21 +++ .../mynet/ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 32 ++++ .../java/com/example/mynet/MainActivity.java | 53 ++++++ .../main/java/com/example/mynet/SendPost.java | 73 ++++++++ .../com/example/mynet/utils/GetAddress.java | 100 ++++++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ app/src/main/res/layout/activity_main.xml | 101 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes app/src/main/res/values-night/themes.xml | 16 ++ app/src/main/res/values/colors.xml | 10 + app/src/main/res/values/strings.xml | 9 + app/src/main/res/values/themes.xml | 16 ++ app/src/main/res/xml/allow_http.xml | 4 + .../com/example/mynet/ExampleUnitTest.java | 17 ++ build.gradle | 24 +++ gradle.properties | 19 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 2 + 43 files changed, 1120 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/mynet/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/mynet/MainActivity.java create mode 100644 app/src/main/java/com/example/mynet/SendPost.java create mode 100644 app/src/main/java/com/example/mynet/utils/GetAddress.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/allow_http.xml create mode 100644 app/src/test/java/com/example/mynet/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.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 +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..23a89bb --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ 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..d5d35ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ 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..73571ce --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "com.example.mynet" + minSdkVersion 22 + 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' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'com.squareup.okhttp3:okhttp:3.14.1' + + +} \ 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/androidTest/java/com/example/mynet/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/mynet/ExampleInstrumentedTest.java new file mode 100644 index 0000000..412d17f --- /dev/null +++ b/app/src/androidTest/java/com/example/mynet/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.mynet; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.mynet", appContext.getPackageName()); + } +} \ 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..a5a5993 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/mynet/MainActivity.java b/app/src/main/java/com/example/mynet/MainActivity.java new file mode 100644 index 0000000..9ed9f87 --- /dev/null +++ b/app/src/main/java/com/example/mynet/MainActivity.java @@ -0,0 +1,53 @@ +package com.example.mynet; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import static com.example.mynet.SendPost.getInfo; +import static com.example.mynet.SendPost.passwordPost; +import static com.example.mynet.utils.GetAddress.getIpAddress; +import static com.example.mynet.utils.GetAddress.getMacAddressFromIp; + +public class MainActivity extends AppCompatActivity { + + private EditText et_password; + private EditText et_name; + private Button bt_login; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + et_name = findViewById(R.id.et_name); + et_password = findViewById(R.id.et_password); + bt_login = findViewById(R.id.bt_login); + + String ipadr = getIpAddress(this); + String macadr = getMacAddressFromIp(this); + + + + + bt_login.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String name = et_name.getText().toString(); + String password = et_password.getText().toString(); + + Log.d("testhttp",name+" "+password); + getInfo(name,password,ipadr,macadr); + SendPost.LoginPost(); + } + }); + + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/mynet/SendPost.java b/app/src/main/java/com/example/mynet/SendPost.java new file mode 100644 index 0000000..f466b1a --- /dev/null +++ b/app/src/main/java/com/example/mynet/SendPost.java @@ -0,0 +1,73 @@ +package com.example.mynet; + +import android.content.Context; +import android.util.Log; + +import java.io.IOException; + +import okhttp3.*; + +import static com.example.mynet.utils.GetAddress.getIpAddress; +import static com.example.mynet.utils.GetAddress.getMacAddressFromIp; + +public class SendPost { + static String TAG = "testhttp"; + static String namePost = null; + static String passwordPost = null; + static String ipPost = null; + static String macPost = null; + + public static void getInfo(String name,String password,String ip ,String mac){ + namePost = name; + passwordPost = password; + ipPost = ip; + macPost = mac; + } + + + + public static void LoginPost(){ + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("application/json"); +// RequestBody body = RequestBody.create(mediaType, "{\"deviceType\":\"PC\",\"webAuthUser\":\"202032908\",\"webAuthPassword\":\"09005X\",\"redirectUrl\":\"http://10.16.0.12:8081/?usermac=4C-6F-9C-02-E2-C5&userip=10.21.91.241&origurl=http://edge.microsoft.com/captiveportal/generate_204&nasip=10.100.0.1\",\"type\":\"login\"}"); + + RequestBody body = RequestBody.create(mediaType, "{\"deviceType\":\"Android\",\"webAuthUser\":\"" + namePost +"\",\"webAuthPassword\":\""+ passwordPost+"\",\"redirectUrl\":\"http://10.16.0.12:8081/?usermac=" + macPost + "&userip="+ ipPost +"&origurl=http://edge.microsoft.com/captiveportal/generate_204&nasip=10.100.0.1\",\"type\":\"login\"}"); + Log.d(TAG,"{\"deviceType\":\"Android\",\"webAuthUser\":\"" + namePost +"\",\"webAuthPassword\":\""+ passwordPost+"\",\"redirectUrl\":\"http://10.16.0.12:8081/?usermac=" + macPost + "&userip="+ ipPost +"&origurl=http://edge.microsoft.com/captiveportal/generate_204&nasip=10.100.0.1\",\"type\":\"login\"}"); + Request request = new Request.Builder() + .url("http://10.16.0.12:8081/portal/api/v2/online?noCache=1605885991204") + .method("POST", body) + .addHeader("accept", "*/*") + .addHeader("accept-encoding", "gzip, deflate") + .addHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6") + .addHeader("authorization", "d258e916aa384de449a489e2abf0642e394dc69548cdbdda602fa64a6f3469de083c110756e9cefd9270b6d7cc354ff123223db4cf860564") + .addHeader("content-length", "251") + .addHeader("content-type", "application/json") +// .addHeader("cookie", "redirectUrl=http://10.16.0.12:8081/?usermac=2C-61-04-FF-73-68&userip=10.22.193.12&origurl=http://edge.microsoft.com/captiveportal/generate_204&nasip=10.100.0.1; token=d258e916aa384de449a489e2abf0642e394dc69548cdbdda602fa64a6f3469de083c110756e9cefd9270b6d7cc354ff123223db4cf860564") + .addHeader("dnt", "1") + .addHeader("host", "10.16.0.12:8081") + .addHeader("origin", "http://10.16.0.12:8081") + .addHeader("proxy-connection", "keep-alive") + .addHeader("referer", "http://10.16.0.12:8081/login") + .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69") + .build(); +// Response response = client.newCall(request).execute(); + client.newCall(request).enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.d(TAG,e.getMessage()); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + Log.d(TAG,"登录成功啦"); + + + + } + }); + } + + +} diff --git a/app/src/main/java/com/example/mynet/utils/GetAddress.java b/app/src/main/java/com/example/mynet/utils/GetAddress.java new file mode 100644 index 0000000..f47f8e5 --- /dev/null +++ b/app/src/main/java/com/example/mynet/utils/GetAddress.java @@ -0,0 +1,100 @@ +package com.example.mynet.utils; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +public class GetAddress { + + public static String getIpAddress(Context context){ + NetworkInfo info = ((ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); + if (info != null && info.isConnected()) { + // 3/4g网络 + if (info.getType() == ConnectivityManager.TYPE_MOBILE) { + try { + for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + + } else if (info.getType() == ConnectivityManager.TYPE_WIFI) { + // wifi网络 + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + String ipAddress = intIP2StringIP(wifiInfo.getIpAddress()); + return ipAddress; + } else if (info.getType() == ConnectivityManager.TYPE_ETHERNET){ + // 有限网络 + return getLocalIp(); + } + } + return null; + } + + private static String intIP2StringIP(int ip) { + return (ip & 0xFF) + "." + + ((ip >> 8) & 0xFF) + "." + + ((ip >> 16) & 0xFF) + "." + + (ip >> 24 & 0xFF); + } + + + // 获取有限网IP + private static String getLocalIp() { + try { + for (Enumeration en = NetworkInterface + .getNetworkInterfaces(); en.hasMoreElements(); ) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf + .getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress() + && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException ex) { + + } + return "0.0.0.0"; + + } + public static String getMacAddressFromIp(Context context) { + String mac_s= ""; + StringBuilder buf = new StringBuilder(); + try { + byte[] mac; + NetworkInterface ne=NetworkInterface.getByInetAddress(InetAddress.getByName(getIpAddress(context))); + mac = ne.getHardwareAddress(); + for (byte b : mac) { + buf.append(String.format("%02X:", b)); + } + if (buf.length() > 0) { + buf.deleteCharAt(buf.length() - 1); + } + mac_s = buf.toString(); + } catch (Exception e) { + e.printStackTrace(); + } + + return mac_s; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..c850ddc --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + +