How to get the Windows IP configuration with command prompt (cmd) using WinForms in C#

1 Answer

0 votes
using System.Diagnostics;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var process = new Process()
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    Arguments = "/c ipconfig",
                    RedirectStandardOutput = true,
                }
            };

            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            MessageBox.Show(output);
        }
    }
}




/*
run:

\r\nWindows IP Configuration\r\n\r\n
\r\nEthernet adapter Ethernet:\r\n\r\n  
Connection-specific DNS Suffix  . : 
\r\n   IPv6 Address. . . . . . . . . . . : ...

*/

 



answered Mar 11, 2024 by avibootz
...