当前位置: 首页>>代码示例>>C#>>正文


C# Ping.Send方法代码示例

本文整理汇总了C#中Ping.Send方法的典型用法代码示例。如果您正苦于以下问题:C# Ping.Send方法的具体用法?C# Ping.Send怎么用?C# Ping.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ping的用法示例。


在下文中一共展示了Ping.Send方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkConnection

    // The state object is necessary for a TimerCallback.
    public void checkConnection(object stateObject)
    {
        Process p = new Process();
        Ping pingSender = new Ping ();
        p.StartInfo.FileName = "arp";
        p.StartInfo.Arguments = "-a";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;

        string data = "a";
         byte[] buffer = Encoding.ASCII.GetBytes (data);

        for(int i = 0; i < 25 ; i++){
            pingSender.Send ("10.0.0."+i.ToString(),10,buffer);
        }

        p.Start();

        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        string MAC = "xx-xx-xx-xx-xx-xx";
        if(output.Contains(MAC)){
            SerialPort port = new SerialPort("COM5", 9600);
            port.Open();
            port.Write("u");
            port.Close();
        }
        else{
            SerialPort port = new SerialPort("COM5", 9600);
            port.Open();
            port.Write("l");
            port.Close();
        }
    }
开发者ID:kurtvonehr,项目名称:ARP-Windows-Service,代码行数:36,代码来源:wifi_doorlock_service.cs

示例2: Main

public static void Main(string [] args)
{
int pingsc = 0, pingf = 0;
int numb = Convert.ToInt32(args[1]);

Ping ping = new Ping();
PingOptions option = new PingOptions();
option.DontFragment = true;

string message = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdfasdfasdfasfasdfasdfasdfasdfasdfas";
byte [] val = Encoding.ASCII.GetBytes(message);
int timeout = 120;
for(int i = 0; i < numb; i++)
{
PingReply reply = ping.Send(args[0], timeout, val, option);
if(reply.Status == IPStatus.Success)
{
Console.WriteLine("Address {0} " , reply.Address.ToString());
Console.WriteLine("RoundTrip time {0} " ,reply.RoundtripTime);
Console.WriteLine("Time to live {0}", reply.Options.Ttl);
Console.WriteLine("Buffer size {0}", reply.Buffer.Length); 
pingsc++;
}
else
{
Console.WriteLine("Ping failed");
pingf++;
}
}
Console.WriteLine("number of Success pings {0}", pingsc);
Console.WriteLine("Number of failed pings {0}", pingf);
}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:32,代码来源:pingClass.cs

示例3: Main

    public static void Main(string[] args)
    {
        using (Ping ping = new Ping())
        {
            try
            {
                PingReply reply = ping.Send("127.0.0.1", 100);

                if (reply.Status == IPStatus.Success)
                {
                    Console.WriteLine("Success - IP Address:{0} Time:{1}ms",
                        reply.Address, reply.RoundtripTime);
                }
                else
                {
                    Console.WriteLine(reply.Status);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error ({0})", ex.InnerException.Message);
            }
        }

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
开发者ID:dbremner,项目名称:hycs,代码行数:27,代码来源:ping.cs

示例4: SendPingAsync_InvalidArgs

        public async Task SendPingAsync_InvalidArgs()
        {
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();
            Ping p = new Ping();

            // Null address
            Assert.Throws<ArgumentNullException>("address", () => { p.SendPingAsync((IPAddress)null); });
            Assert.Throws<ArgumentNullException>("hostNameOrAddress", () => { p.SendPingAsync((string)null); });
            Assert.Throws<ArgumentNullException>("address", () => { p.SendAsync((IPAddress)null, null); });
            Assert.Throws<ArgumentNullException>("hostNameOrAddress", () => { p.SendAsync((string)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { p.Send((IPAddress)null); });
            Assert.Throws<ArgumentNullException>("hostNameOrAddress", () => { p.Send((string)null); });

            // Invalid address
            Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.Any); });
            Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.IPv6Any); });
            Assert.Throws<ArgumentException>("address", () => { p.SendAsync(IPAddress.Any, null); });
            Assert.Throws<ArgumentException>("address", () => { p.SendAsync(IPAddress.IPv6Any, null); });
            Assert.Throws<ArgumentException>("address", () => { p.Send(IPAddress.Any); });
            Assert.Throws<ArgumentException>("address", () => { p.Send(IPAddress.IPv6Any); });

            // Negative timeout
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(localIpAddress, -1); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(TestSettings.LocalHost, -1); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendAsync(localIpAddress, -1, null); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendAsync(TestSettings.LocalHost, -1, null); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.Send(localIpAddress, -1); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.Send(TestSettings.LocalHost, -1); });

            // Null byte[]
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(localIpAddress, 0, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 0, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendAsync(localIpAddress, 0, null, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendAsync(TestSettings.LocalHost, 0, null, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.Send(localIpAddress, 0, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.Send(TestSettings.LocalHost, 0, null); });

            // Too large byte[]
            Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(localIpAddress, 1, new byte[65501]); });
            Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 1, new byte[65501]); });
            Assert.Throws<ArgumentException>("buffer", () => { p.SendAsync(localIpAddress, 1, new byte[65501], null); });
            Assert.Throws<ArgumentException>("buffer", () => { p.SendAsync(TestSettings.LocalHost, 1, new byte[65501], null); });
            Assert.Throws<ArgumentException>("buffer", () => { p.Send(localIpAddress, 1, new byte[65501]); });
            Assert.Throws<ArgumentException>("buffer", () => { p.Send(TestSettings.LocalHost, 1, new byte[65501]); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:45,代码来源:PingTest.cs

示例5: Status

 public static String Status(String IP)
 {
     IPAddress ip = IPAddress.Parse(IP);
         try
         {
             Ping ping = new Ping();
             PingReply reply = ping.Send(ip);
             return Convert.ToString(reply.Status);
         }
         catch(Exception)
         {
             return "Error";
         }
 }
开发者ID:he110,项目名称:PrintScaner,代码行数:14,代码来源:PrParser.cs

示例6: Main

	static void Main (string [] args)
	{
		Ping pingSender = new Ping ();
		PingOptions options = new PingOptions ();

		// Use the default Ttl value which is 128,
		// but change the fragmentation behavior.
		options.DontFragment = true;

		// Create a buffer of 32 bytes of data to be transmitted.
		string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
		byte [] buffer = Encoding.ASCII.GetBytes (data);
		int timeout = 120;
		PingReply reply = pingSender.Send (args [0], timeout, buffer, options);
		Console.WriteLine ("Status: {0}", reply.Status);
	}
开发者ID:mono,项目名称:gert,代码行数:16,代码来源:sync.cs

示例7: CheckInternetConnection

 public bool CheckInternetConnection(String ipAddress)
 {
     bool result = false;
     Ping p = new Ping();
     try
     {
         PingReply reply = p.Send(ipAddress, 1000);
         if (reply.Status == IPStatus.Success)
         {
             result = true;
         }
     }
     catch (PingException)
     {
         result = false;
     }
     return result;
 }
开发者ID:jimiejosh,项目名称:BES10-Cascades,代码行数:18,代码来源:Default.aspx.cs

示例8: Connect

    public static ICSharpRpcClient Connect(string ipaddress)
    {
        Ping pinger = new Ping();
        PingReply pr = pinger.Send(ipaddress);

        if (pr.Status == IPStatus.Success)
        {
            Console.WriteLine("Connect to {0}", ipaddress);

            newProxy = XmlRpcProxyGen.Create<ICSharpRpcClient>();
            string newProxyUrl = ServerUrlStart + ipaddress + ServerUrlEnd;
            newProxy.Url = newProxyUrl;

            Console.WriteLine("XML-RPC Client call to : http://" + ipaddress + ":1090/xmlrpc/xmlrpc");

            return newProxy;
        }
        else
        {
            return null;
        }
    }
开发者ID:UkiMiawz,项目名称:data-communication,代码行数:22,代码来源:XmlrpcHelper.cs

示例9: CheckHostAlive

                private void CheckHostAlive()
                {
                    Ping pingSender = new Ping();
                    PingReply pReply;

                    try
                    {
                        pReply = pingSender.Send(HostName);

                        if (pReply.Status == IPStatus.Success)
                        {
                            if ((string)this.btnHostStatus.Tag == "checking")
                            {
                                ShowStatusImage(global::My.Resources.Resources.HostStatus_On);
                            }
                        }
                        else
                        {
                            if ((string)this.btnHostStatus.Tag == "checking")
                            {
                                ShowStatusImage(global::My.Resources.Resources.HostStatus_Off);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if ((string)this.btnHostStatus.Tag == "checking")
                        {
                            ShowStatusImage(global::My.Resources.Resources.HostStatus_Off);
                        }
                    }
                }
开发者ID:jpmarques,项目名称:mRemoteNC,代码行数:32,代码来源:UI.Window.Config.cs

示例10: Sends_ReuseInstance_Hostname

        public static async Task Sends_ReuseInstance_Hostname()
        {
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();

            using (Ping p = new Ping())
            {
                for (int i = 0; i < 3; i++)
                {
                    PingReply pingReply = p.Send(TestSettings.LocalHost);
                    Assert.Equal(IPStatus.Success, pingReply.Status);
                    Assert.True(pingReply.Address.Equals(localIpAddress));
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:PingTest.cs

示例11: triggerButton_Click

    protected void triggerButton_Click(object sender, EventArgs e)
    {
        if(Page.IsPostBack)
        {
            LabelInfo.Text = "正在处理中,请稍等。。。";
            triggerButton.Enabled = false;

            //服务器IP
            List<ServerInfo> list = new List<ServerInfo>();
            ServerInfo info1 = new ServerInfo();
            info1.Port = 0xca4d;
            info1.Ip = "112.132.215.30";
            list.Add(info1);
            ServerInfo info2 = new ServerInfo();
            info2.Port = 0x6bb0;
            info2.Ip = "112.213.122.141";
            list.Add(info2);
            ServerInfo info3 = new ServerInfo();
            info3.Port = 0xdba6;
            info3.Ip = "117.25.147.236";
            list.Add(info3);
            ServerInfo info4 = new ServerInfo();
            info4.Port = 0xd1c3;
            info4.Ip = "112.132.212.59";
            list.Add(info4);
            ServerInfo info5 = new ServerInfo();
            info5.Port = 0x4ec0;
            info5.Ip = "206.161.218.27";
            list.Add(info5);
            ServerInfo info6 = new ServerInfo();
            info6.Port = 0xccb1;
            info6.Ip = "211.55.29.30";
            list.Add(info6);

            string curIp = "117.25.147.236";
            int curPort = 0xdba6;
            Ping curP = new Ping();
            if (curP.Send(curIp).Status != IPStatus.Success)
            {
                foreach (ServerInfo si in list){
                    Ping p = new Ping();
                    if (p.Send(si.Ip).Status == IPStatus.Success)
                    {
                        curIp = si.Ip;
                        curPort = si.Port;
                    }
                }
                if (curIp == "117.25.147.236")
                {
                    LabelInfo.Text = "网络不通,连接服务器失败";
                    triggerButton.Enabled = true;
                    return;
                }
            }

            short UserType = 0;
            string errMsg = string.Empty;
            if (RadioButton1.Checked)
            {
                UserType = 1;
            }

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //EndPoint point = new IPEndPoint(IPAddress.Parse("117.25.147.236"), 0xdba6);
            EndPoint point = new IPEndPoint(IPAddress.Parse(curIp), curPort);
            s.Connect(point);

            if (!s.Connected)
            {
                // Connection failed, try next IPaddress.
                s = null;
                LabelInfo.Text = "网络不通,连接服务器失败";
                triggerButton.Enabled = true;
                return;
            }
            else
            {
                /********************登陆********************/
                LoginInfo li = new LoginInfo();
                li.UserName = ConfigurationManager.AppSettings["user"];
                li.Password = Encrypt.sEncrypt(ConfigurationManager.AppSettings["pwd"]);
                li.Ver = "2.0.1";

                //Send(0x80001, li.GetBytes())
                byte[] datal = li.GetBytes();
                int sizel = datal.Length;
                int offsetl = 0;
                int msgl = 0x80001;

                byte[] destinationArrayl = new byte[sizel + 8];
                Array.Copy(BitConverter.GetBytes(msgl), 0, destinationArrayl, 0, 4);
                Array.Copy(BitConverter.GetBytes(sizel), 0, destinationArrayl, 4, 4);
                if ((datal != null) && (datal.Length >= (offsetl + sizel)))
                {
                    Array.Copy(datal, offsetl, destinationArrayl, 8, sizel);
                }
                try
                {
                    s.Send(destinationArrayl, destinationArrayl.Length, 0);//发包
                    byte[] buf = new byte[1024];
//.........这里部分代码省略.........
开发者ID:eddy8,项目名称:eddy,代码行数:101,代码来源:Default.aspx.cs

示例12: btnVirusScan_Click

    protected void btnVirusScan_Click(object sender, System.EventArgs e)
    {
        clearConsole();

        // DECLARE OBJECTS AND VARIABLES
        Thread clamavThread = new Thread(clamScanThread);
        Thread clamavInstallationThread = new Thread(clamavInstallThread);

        // ADDRESS REPRESENTS UBUNTU UPDATE MIRROR, FAILING TO CONNECT
        // WILL HALT THE UPDATE PROCESS TO PROTECT THE SYSTEM
        string host = "archive.ubuntu.com";
        Ping p = new Ping();

        if (File.Exists(CLAMSCAN_BIN))
        {
            // CLAMAV IS INSTALLED, BEGIN VIRUS SCAN
            clamavThread.Start();

            progressBarPulse();
        }
        else
        {
            // CLAMAV IS NOT INSTALLED
            // DETECT NETWORK CONNECTION BEFORE ATTEMPTING INSTALLATION
            try
            {
                PingReply reply = p.Send(host, 1000);
                if (reply.Status == IPStatus.Success)
                {
                    // INTERNET CONENCTION EXISTS
                    // INSTALL SOFTWARE
                    clamavInstallationThread.Start();

                    progressBarPulse();
                }
            }
            catch
            {
                // INTERNET CONNECTION DOES NOT EXIST
                MessageDialog mBoxError = new MessageDialog (this,
                    DialogFlags.DestroyWithParent,
                    MessageType.Error,
                    ButtonsType.Close,
                    "ClamAV is not installed. An active Internet connection was not detected. Please connect to the Internet to install ClamAV.");
                mBoxError.Run();
                mBoxError.Destroy();
            }
        }
    }
开发者ID:ultraviolet-1986,项目名称:LinuxSecurityCenter,代码行数:49,代码来源:frmMain.cs

示例13: btnRefreshPackageCatalog_Click

    protected void btnRefreshPackageCatalog_Click(object sender, System.EventArgs e)
    {
        clearConsole();

        // DECLARE OBJECTS AND VARIABLES
        Thread aptGetUpdateThread = new Thread(updateThread);

        // ADDRESS REPRESENTS UBUNTU UPDATE MIRROR, FAILING TO CONNECT
        // WILL HALT THE UPDATE PROCESS TO PROTECT THE SYSTEM
        string host = "archive.ubuntu.com";
        Ping p = new Ping();

        try
        {
            PingReply reply = p.Send(host, 1000);
            if (reply.Status == IPStatus.Success)
            {
                // INTERNET CONENCTION EXISTS
                // INSTALL SOFTWARE
                aptGetUpdateThread.Start();

                progressBarPulse();
            }
        }
        catch
        {
            // DISPLAY ERROR WINDOW
            noInternetConnection();
        }
    }
开发者ID:ultraviolet-1986,项目名称:LinuxSecurityCenter,代码行数:30,代码来源:frmMain.cs

示例14: btnFreshclam_Click

    protected void btnFreshclam_Click(object sender, System.EventArgs e)
    {
        clearConsole();

        // UPDATE VIRUS DEFINITIONS
        Thread updateClamavThread = new Thread(freshclamThread);

        // ADDRESS REPRESENTS CLAMAV UPDATE MIRROR, FAILING TO CONNECT
        // WILL HALT THE UPDATE PROCESS TO PROTECT THE SYSTEM
        string host = "clamav.net";
        Ping p = new Ping();

        try
        {
            PingReply reply = p.Send(host, 1000);
            if (reply.Status == IPStatus.Success)
            {
                // INTERNET CONNECTION EXISTS
                updateClamavThread.Start();

                // BEGIN PULSING THE PROGRESS BAR
                progressBarPulse();
            }
        }
        catch
        {
            // DISPLAY ERROR WINDOW
            noInternetConnection();
        }
    }
开发者ID:ultraviolet-1986,项目名称:LinuxSecurityCenter,代码行数:30,代码来源:frmMain.cs


注:本文中的Ping.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。