Asp.net calls cmd and queries ip information
Private static string dig Ping (string cmd)
{
Process p = new process ();
P. startinfo. filename = "cmd.exe ";
P. startinfo. useshellexecute = false;
P. startinfo. redirectstandardinput = true;
P. startinfo. redirectstandardoutput = true;
P. startinfo. redirectstandarderror = true;
P. startinfo. createnowindow = true;
String pingrst;
P. start ();
P. standardinput. writeline (cmd );
P. standardinput. writeline ("exit ");
String strrst = p. standardoutput. readtoend ();
Pingrst = strrst;
// If end
P. close ();
Return pingrst;
}
// Method 2
Private string runcmd (string command)
{
// A process class of the instance to start an independent process
Process p = new process ();
// The process class has a startinfo attribute. This is the processstartinfo class, which includes some attributes and methods. Below we use several of its attributes:
P. startinfo. filename = "cmd.exe"; // set the program name
P. startinfo. arguments = "/c" + command; // Set program execution parameters
P. startinfo. useshellexecute = false; // Close shell usage
P. startinfo. redirectstandardinput = true; // redirect standard input
P. startinfo. redirectstandardoutput = true; // redirect standard output
P. startinfo. redirectstandarderror = true; // redirect error output
P. startinfo. createnowindow = true; // you can specify not to display a window.
P. start (); // start
// P. standardinput. writeline (command); // you can enter the command to be executed in this way.
// P. standardinput. writeline ("exit"); // however, remember to add exit. Otherwise, the next line of code will go live when it is executed.
Return p. standardoutput. readtoend (); // Obtain the command execution result from the output stream
// Other methods
System.net. dns. gethostaddresses ("");
// You can get all the IP addresses of the local machine...