Solved

ipconfig,Ping,nsloookup programs

Posted on 2003-11-21
3
949 Views
Last Modified: 2011-10-03
Does anyone know of ways to use these applications (ipconfig,ping,nslookup) within C#. I want to use these applications in the background and don't want the user to see usage of these applications. Thanks for any help.
0
Comment
Question by:andyk1
  • 2
3 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 9799816


using System.Diagnostics;



            private void DOSCommand()
            {            
                  Process myDosCmd = null;
                  ProcessStartInfo qOptions = new ProcessStartInfo("cmd.exe", @"/C net send pc-02-49 This is a text Message");
                  qOptions.RedirectStandardOutput = false;  // set to "true" to enable logging
                  qOptions.UseShellExecute = true;  // set to true to make silent/background
                  qOptions.WindowStyle = ProcessWindowStyle.Hidden;

                  myDosCmd = Process.Start(qOptions);
                  myDosCmd.WaitForExit();
                  
                  //Logging commands
//                  string dosOut = DOS.StandardOutput.ReadToEnd();
//                  Console.Write(dosOut);
            }
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 75 total points
ID: 9799880


The above code is for the net send command but everything else works exactly the same.

Here is the code (altered slightly) to ping my own computer (although the window is not hidden like you would expect it to be)

:-(



            private void DOSCommand()
            {            
                  Process myDosCmd = null;
                  ProcessStartInfo qOptions = new ProcessStartInfo("cmd.exe", @"/C ping pc-02-49");
                  qOptions.WindowStyle = ProcessWindowStyle.Hidden;
                  qOptions.RedirectStandardOutput = true;  // set to "true" to enable logging
                  qOptions.UseShellExecute = false;  // set to true to make silent/background
                  
                  myDosCmd = Process.Start(qOptions);
                  myDosCmd.WaitForExit();
                  
                  //Logging commands
                  string dosOut = myDosCmd.StandardOutput.ReadToEnd();
                  Console.Write(dosOut);
            }



---Console---



Pinging PC-02-49.jsi.jc.com [10.1.63.10] with 32 bytes of data:



Reply from 10.1.63.10: bytes=32 time<1ms TTL=128

Reply from 10.1.63.10: bytes=32 time<1ms TTL=128

Reply from 10.1.63.10: bytes=32 time<1ms TTL=128

Reply from 10.1.63.10: bytes=32 time<1ms TTL=128



Ping statistics for 10.1.63.10:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms

0
 
LVL 1

Expert Comment

by:nettnerd
ID: 9800185
If your interested in getting results within your program Check this link out.  Im sure there is code available for IpConfig / NSLookup Type Programs.
http://www.christopherlewis.com/Code/Ping/ping.cs.source
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question