code androi get ip Lan

Get ip lan bang lenh arp -a
 avatar
user_8607526207
csharp
3 years ago
5.0 kB
4
Indexable
Bui Van Tien, [29/11/2022 9:00 SA]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
 
namespace WindowsFormsApp9
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private extern static void ReleaseCapture();
        [DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool MoveWindow(IntPtr hnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
        public IntPtr hnd;
        Process process = new Process();
        ProcessStartInfo info = new ProcessStartInfo();
        public Form1()
        {
            InitializeComponent();
            info.CreateNoWindow = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
        }
 
        private void tao_cua_so(Process process)
        {
            Panel panel = new Panel();
            panel.Width = 200;
            panel.Height = 300;
            panel.BackColor = Color.White;
            panel.BorderStyle = BorderStyle.FixedSingle;
            this.Invoke(new Action(() =>
            {
                flowLayoutPanel1.Controls.Add(panel);
                IntPtr d = process.MainWindowHandle;
                SetParent(d, panel.Handle);
                var x = d;
 
                MoveWindow(d, 0, -33, panel.Width, panel.Height + 60, true);
            }));
        }
 
 
 
 
        private void button1_Click(object sender, EventArgs e)
        {
            Process[] processlist = Process.GetProcesses();
            foreach (Process process in processlist)
            {
                //scrcpy.exe -s ce061716d1440205017e --window-width 200 --window-height 300 --window-title z483
                if (process.MainWindowTitle.Contains("z483") && process.ProcessName.Contains("scrcpy") )
                {
                    tao_cua_so(process);
                }
            }
 
            //Panel panel = new Panel();
            //panel.Width = 200;
            //panel.Height = 300;
            //panel.BackColor = Color.White;
            //panel.BorderStyle = BorderStyle.FixedSingle;
            //this.Invoke(new Action(() =>
            //{
            //    flowLayoutPanel1.Controls.Add(panel);
            //}));
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            thoat();
        }
 
        private void thoat()
        {
            foreach (Process process in getProcessList())
            {
                if (process.MainWindowTitle.Contains("z483") && process.ProcessName.Contains("scrcpy"))
                {
                    process.Close();
                }
            }
            Application.Exit();
        }
 
        private Process[] getProcessList()
        {
            Process[] processlist = Process.GetProcesses();
            return processlist;
        }
 
        private void bt_getID_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            string command = "devices";
            String[] listDevices = splitString(runCommandAdb(command));
            foreach (var item in listDevices)
            {
                listDevices = item.Split("\t".ToCharArray(), StringSplitOptions.None);
                listDevices = listDevices.Where((val, idx) => val != "device").ToArray();
                foreach (var devicesCur in listDevices)
                {
                    if (devicesCur != "")
                    {
                        listBox1.Items.Add(devicesCur);
                    }
                }
            }

Bui Van Tien, [29/11/2022 9:00 SA]
}
        private string runCommandAdb(string command)
        {
            info.FileName = "adb.exe";
            info.Arguments = command;
            process.StartInfo = info;
            process.Start();
            return process.StandardOutput.ReadToEnd();
        }
        private  string[] splitString(string resultFormadbCommand)
        {
            string [] listDevices = resultFormadbCommand.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            listDevices = listDevices.Where((val, idx) => idx != 0).ToArray();
            return listDevices;
        }
        private void bt_run_Click(object sender, EventArgs e)
        {
            
        }
    }
}
Editor is loading...