Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.comsoft.getinetinfo;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.app.ActivityCompat;
- import androidx.core.content.ContextCompat;
- import android.Manifest;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void onClickGetInfo(View v) {
- new Thread(new Runnable() {
- public void run() {
- try {
- URL url = new URL("https://yandex.ru/internet/");
- BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
- String result = "";
- String line = "";
- while ((line = reader.readLine()) != null){
- result += line + "\n";
- }
- reader.close();
- int p = result.indexOf("IPv4-адрес</h3></div><div>");
- result = result.substring(p + "IPv4-адрес</h3></div><div>".length());
- p = result.indexOf("</div>");
- result = result.substring(0, p);
- TextView editText = (TextView) findViewById(R.id.display);
- editText.setText(result);
- }catch (Exception e){
- }
- };
- }).start();
- }
- }
Add Comment
Please, Sign In to add comment