Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Ping in .NET 1.1

Ping in .NET 1.1

Scheduled Pinned Locked Moved C#
csharpdotnetvisual-studiohelpquestion
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartyExodus
    wrote on last edited by
    #1

    I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

    E P D L N 5 Replies Last reply
    0
    • M MartyExodus

      I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      You should have put "ping" in the search bar. You would have found this: http://www.codeproject.com/dotnet/CSharpPing.asp

      1 Reply Last reply
      0
      • M MartyExodus

        I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I suppose you could access a v2.0 assembly (dll) from a v1.1 executable. The method I have that wraps the ping is: public static System.Net.NetworkInformation.IPStatus Ping ( string HostName ) { System.Net.NetworkInformation.IPStatus result = System.Net.NetworkInformation.IPStatus.Unknown ; try { result = (new System.Net.NetworkInformation.Ping()).Send ( HostName , 1000 ).Status ; } catch { } return ( result ) ; } You don't even need the express version, just the SDK.

        1 Reply Last reply
        0
        • M MartyExodus

          I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

          D Offline
          D Offline
          Dan Neely
          wrote on last edited by
          #4

          You can use the StandardOutput property of the Process class to capture the output of a commandline application.

          -- Rules of thumb should not be taken for the whole hand.

          M 1 Reply Last reply
          0
          • D Dan Neely

            You can use the StandardOutput property of the Process class to capture the output of a commandline application.

            -- Rules of thumb should not be taken for the whole hand.

            M Offline
            M Offline
            MartyExodus
            wrote on last edited by
            #5

            Ha. Thank you everyone for your quick responses. However, I'm still having a slight problem, possibly due to that fact that i didn't articulate my original problem. ednrgc and PIEBALDconsult - The reason that i didn't do as the two of you said is simply this: System.Net.NetworkInformation doesn't exist in .NET 1.1, and as such, the Ping class doesn't exist either (Or I possibly don't know how to access them, but I'm pretty sure I'm right) dan neely - I believe this method will work, however, I'm rather uncertain as to HOW to use it. This is what I have so far:

            using System;
            using System.Diagnostics;
            using System.IO;

            private void ping(string computer)
            {
            string args = "/k ping " + computer;
            Process p = new System.Process()
            ProcessStartInfo ps = new ProcessStartInfo("cmd", args);
            p.StartInfo = ps;
            p.Start();
            StreamReader s = p.StandardOutput;
            MessageBox.Show(s.Readline);
            }

            The command prompt loads correctly, but alas, the StreamReader fails, and the MessageBox does not show. It generates an InvalidOperationException, and simply states "StandardOutput has not been redirected." Thanks everyone again for the quick response, and hopefully, you can help me further. Thanks, MartyExodus

            L P 2 Replies Last reply
            0
            • M MartyExodus

              Ha. Thank you everyone for your quick responses. However, I'm still having a slight problem, possibly due to that fact that i didn't articulate my original problem. ednrgc and PIEBALDconsult - The reason that i didn't do as the two of you said is simply this: System.Net.NetworkInformation doesn't exist in .NET 1.1, and as such, the Ping class doesn't exist either (Or I possibly don't know how to access them, but I'm pretty sure I'm right) dan neely - I believe this method will work, however, I'm rather uncertain as to HOW to use it. This is what I have so far:

              using System;
              using System.Diagnostics;
              using System.IO;

              private void ping(string computer)
              {
              string args = "/k ping " + computer;
              Process p = new System.Process()
              ProcessStartInfo ps = new ProcessStartInfo("cmd", args);
              p.StartInfo = ps;
              p.Start();
              StreamReader s = p.StandardOutput;
              MessageBox.Show(s.Readline);
              }

              The command prompt loads correctly, but alas, the StreamReader fails, and the MessageBox does not show. It generates an InvalidOperationException, and simply states "StandardOutput has not been redirected." Thanks everyone again for the quick response, and hopefully, you can help me further. Thanks, MartyExodus

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              If I had to spawn a child process to ping a remote computer I would never write code again. But that's just me I guess. http://en.wikipedia.org/wiki/Ping[^] http://www.eggheadcafe.com/articles/20020209.asp[^]

              led mike

              M 1 Reply Last reply
              0
              • M MartyExodus

                I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Well I once did my own ping in .NET 1.1 Her is the code; it will only compile and run within my environment, but I'll show it anyway. env.log() is just a logging function, and can be ignored (or used!) class LP_Format does string formatting, is obvious class LP_Thread basically is Thread, LP_BackgroundThread is derived from Thread (sets IsBackground and calls Start). remark: this is not thread-safe (since I use a static pingResult internally), but that could easily be solved.

                public static bool Ping(string remoteIPadrString) {
                pingResult=false;
                LP_BackgroundThread thread=new LP_BackgroundThread("PING("+remoteIPadrString+")",
                new LP_ObjectHandler(Pinger), remoteIPadrString);
                if (!thread.Join(10000)) {
                env.log(0, "Aborting PING("+remoteIPadrString+") due to timeout");
                //thread.Abort();
                LP_Thread.Sleep(1000);
                }
                return pingResult;
                }

                protected static bool pingResult;

                protected static void Pinger(object arg) {
                string remoteIPadrString=arg as string;
                env.log(0, "---------");
                env.log(0, "Ping("+remoteIPadrString+")");
                IPAddress remoteIPadr=IPAddress.Parse(remoteIPadrString);
                pingResult=false;
                Socket socket=null;
                try {
                env.log(env.DETAIL2, "remoteIPadr="+remoteIPadr.ToString());
                IPAddress[] IPAS=getIPAddresses();
                env.log(env.DETAIL2, "got IP addresses");
                socket=null;
                foreach (IPAddress IPA in IPAS) {
                try {
                env.log(env.DETAIL2, "Ping("+remoteIPadrString+") using "+IPA.ToString());
                socket=new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
                socket.Blocking=false;
                env.log(env.DETAIL1, "got socket");
                EndPoint localEP=new IPEndPoint(IPA, IPEndPoint.MinPort);
                EndPoint remoteEP=new IPEndPoint(remoteIPadr, IPEndPoint.MinPort);
                socket.Bind(localEP);
                ushort[] sdata=new ushort[20];
                sdata[0]=0x0800; // ICMP echo request
                sdata[1]=0; // ICMP checksum
                sdata[2]=0x0100; // ICMP identifier
                sdata[3]=0x0400; // ICMP sequence number
                ushort val=0x6162;
                for (int j=0; j<16; j++) {
                sdata[j+4]=val;
                val+=0x0202;
                if (val==0x7963) val=0x6263;
                if (val==0x7778) val=0x7761;
                }
                sdata[1]=ICMPchecksum(sdata);
                env.log(env.DETAIL2,"checksum="+LP_Format.Hex4(sdata[1]));
                byte[] bdata=new byte[40];
                for (int j=0; j<20; j++) {
                bdata[2*j]=(byte)((sdata[j]>>8)&0xFF);
                bdata[2*j+1]=(byte)(sdata[j]&0xFF);
                }
                bool dump=false;
                int len=socket.SendTo(bdata, remoteEP);
                env.log(env.DETAIL1, "sent");
                if (

                1 Reply Last reply
                0
                • L led mike

                  If I had to spawn a child process to ping a remote computer I would never write code again. But that's just me I guess. http://en.wikipedia.org/wiki/Ping[^] http://www.eggheadcafe.com/articles/20020209.asp[^]

                  led mike

                  M Offline
                  M Offline
                  MartyExodus
                  wrote on last edited by
                  #8

                  Hey, thanks a lot. While I'm not using the exact code from the article you posted... (simply because I'd like to LEARN rather than simply USE) you've inspired me to learn how to use sockets - something I should have done a long time ago. But again, thanks to all who posted. -MartyExodus

                  L 1 Reply Last reply
                  0
                  • M MartyExodus

                    Ha. Thank you everyone for your quick responses. However, I'm still having a slight problem, possibly due to that fact that i didn't articulate my original problem. ednrgc and PIEBALDconsult - The reason that i didn't do as the two of you said is simply this: System.Net.NetworkInformation doesn't exist in .NET 1.1, and as such, the Ping class doesn't exist either (Or I possibly don't know how to access them, but I'm pretty sure I'm right) dan neely - I believe this method will work, however, I'm rather uncertain as to HOW to use it. This is what I have so far:

                    using System;
                    using System.Diagnostics;
                    using System.IO;

                    private void ping(string computer)
                    {
                    string args = "/k ping " + computer;
                    Process p = new System.Process()
                    ProcessStartInfo ps = new ProcessStartInfo("cmd", args);
                    p.StartInfo = ps;
                    p.Start();
                    StreamReader s = p.StandardOutput;
                    MessageBox.Show(s.Readline);
                    }

                    The command prompt loads correctly, but alas, the StreamReader fails, and the MessageBox does not show. It generates an InvalidOperationException, and simply states "StandardOutput has not been redirected." Thanks everyone again for the quick response, and hopefully, you can help me further. Thanks, MartyExodus

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    MartyExodus wrote:

                    PIEBALDconsult - The reason that i didn't do as the two of you said is simply this: System.Net.NetworkInformation doesn't exist in .NET 1.1,

                    I understand that. But I meant compile the method into its own v2.0 dll and reference it from your v1.1 executable. You said you have the Express version so you must have the v2.0 dlls and compiler. I haven't tried it, nor do I have a way to try it.

                    1 Reply Last reply
                    0
                    • M MartyExodus

                      Hey, thanks a lot. While I'm not using the exact code from the article you posted... (simply because I'd like to LEARN rather than simply USE) you've inspired me to learn how to use sockets - something I should have done a long time ago. But again, thanks to all who posted. -MartyExodus

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      MartyExodus wrote:

                      simply because I'd like to LEARN rather than simply USE

                      Then you have a bright future! :cool:

                      led mike

                      1 Reply Last reply
                      0
                      • M MartyExodus

                        I am writing a program in Visual Studio .NET 2003, and as such I am using version 1.1 of the .NET Framework. I need to include a function to ping a remote computer, and, while it is easy enough to pass it into the command prompt, I don't know of any way to read the result of the ping attempt. MSDN says that there is a Ping class in .NET 2.0 and 3.0 (System.Net.NetworkInformation.Ping - system.dll), but that doesn't really help me, as it's not in .NET 1.1 Is there any way I can import the functionality from .NET 2.0 (I have the Framwork and C# 2005 Express installed), or is there any other way to ping and receive a result? I would really appreciate some help with this, as I need to make this program for work.... and I need to have it done by Monday afternoon. Thanks again, MartyExodus

                        N Offline
                        N Offline
                        Nader Elshehabi
                        wrote on last edited by
                        #11

                        MartyExodus wrote:

                        Is there any way I can import the functionality from .NET 2.0

                        Sure! 1- First install DotNet 2.0 on your machine. 2- Then add a reference to your project. Choose browse. 3- Browse to the DotNet 2.0 folder -I believe it's under "windows\system32"-. and choose the assembly you want to reference. 4- In your case the assembly should be "System.Net.NetworkInformation.dll". PS. If you do this then DotNet 2.0 should also be installed on the user's machine.

                        Regards:rose:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups