Quantcast
Channel: how to separate/filter an output string and write the separated data into different text boxes? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

how to separate/filter an output string and write the separated data into different text boxes?

$
0
0

So i have a button and two text boxes. I want to click a button, it will execute nslookup then i want to :

-write the resolved hostname into one text box
-write the resolved ip adress into next text box 

I have this so far

    System.Diagnostics.Process p = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                psi.FileName = "nslookup.exe";
                psi.Arguments = "google.com";

                psi.RedirectStandardOutput = true;
                psi.UseShellExecute = false;

                psi.CreateNoWindow = false;
                p.StartInfo = psi;
                p.Start();

                p.WaitForExit();

                System.IO.StreamReader output = p.StandardOutput;

                textbox1.Text = output.ReadToEnd().ToString();

So now it does the resolution and writes everything into one string. How can i filter the output string and write specific parts of the string into separate boxes ?

Example output string will be : ( it is a single line string but i wrote it here in a table for easy understanding )

Server:  EXAMPLE //this i dont need
Address:  EXAMPLE //this i dont need

Name:    google.com //i need this to be written to TextBox1
Address: 172.217.21.206 //i need this to be written to TextBox2

So that in the end :

Textbox.Text = "google.com"
Textbox2.Text = "172.217.21.206"

Later i want to ping the ip in textbox2 and make the text box change color if its reachable, and a button to rdp connect to that ip if its reachable, so i need it to not have any spaces and just be a string

I was thinking to write each word that is separated by a space into an array and then read the array and write things that match into the boxes with something like this :

string[] words = outputstring.Split(' ');

        foreach (var word in words)
        {
            System.Console.WriteLine($"<{word}>");
        }

But before i continue with it i wanted to ask if there is an easier and faster way to do it and im going in the wrong direction alltogether ? maybe there is a way to just return specific parameters out of the nslookup command ?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images