Asp.net calls cmd and queries IP information

Source: Internet
Author: User

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.