免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
c#實(shí)現(xiàn)驗(yàn)證某個(gè)IP地址是否能ping通
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading;
namespace Manager.Common
{
public static class NetCommon{
        /// <summary>
        /// 驗(yàn)證IP地址字符串的正確性
        /// </summary>
        /// <param name="strIP">要驗(yàn)證的IP地址字符串</param>
        /// <returns>格式是否正確,正確為 true 否則為 false</returns>
        public static bool CheckIPAddr(string strIP)
        {
            if (string.IsNullOrEmpty(strIP))
            {
                return false;
            }
            // 保持要返回的信息
            bool bRes = true;
            int iTmp = 0;    // 保持每個(gè)由“.”分隔的整型
            string[] ipSplit = strIP.Split('.');
            if (ipSplit.Length < 4 || string.IsNullOrEmpty(ipSplit[0]) ||
                string.IsNullOrEmpty(ipSplit[1]) ||
                string.IsNullOrEmpty(ipSplit[2]) ||
                string.IsNullOrEmpty(ipSplit[3]))
            {
                bRes = false;
            }
            else
            {
                for (int i = 0; i < ipSplit.Length; i++)
                {
                    if (!int.TryParse(ipSplit[i], out iTmp) || iTmp < 0 || iTmp > 255)
                    {
                        bRes = false;
                        break;
                    }
                }
            }

            return bRes;
        }
        /// <summary>
        /// 驗(yàn)證某個(gè)IP是否可ping通
          /// </summary>
        /// <param name="strIP">要驗(yàn)證的IP</param>
        /// <returns>是否可連通  是:true 否:false</returns>
        public static bool TestNetConnectity(string strIP)
        {
            if (!NetUtil.CheckIPAddr(strIP))
            {
                return false;
            }
            // Windows L2TP VPN和非Windows VPN使用ping VPN服務(wù)端的方式獲取是否可以連通
            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 = "testtesttesttesttesttesttesttest";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            PingReply reply = pingSender.Send(strIP, timeout, buffer, options);

            return (reply.Status == IPStatus.Success);
        }
        /// <summary>
        /// 連續(xù)幾次查看是否某個(gè)IP可以PING通
        /// </summary>
        /// <param name="strIP">ping的IP地址</param>
        /// <param name="WaitSecond">每次間隔時(shí)間,單位:秒</param>
        /// <param name="iTestTimes">測試次數(shù)</param>
        /// <returns>是否可以連通</returns>
        public static bool TestNetConnected(string strIP, int WaitSecond, int iTestTimes)
        {
            for (int i = 0; i < iTestTimes - 1; i++)
            {
                if (TestNetConnectity(strIP))
                {
                    return true;
                }
                Thread.Sleep(WaitSecond * 1000);
            }

            return TestNetConnectity(strIP);
        }
}
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
掃描局域網(wǎng)mac地址
C#的網(wǎng)絡(luò)適配器操作
比較核心的技術(shù)了 虛擬ip的一種實(shí)現(xiàn)方式(手工添加和C#添加)
如何進(jìn)入那些被屏蔽的網(wǎng)站(你們懂的網(wǎng)站)
js驗(yàn)證IP地址
C# 登錄簡單網(wǎng)站嘗試 — Windows Live
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服