posts - 124,  comments - 29,  trackbacks - 0

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;

namespace PingIpAddress
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
           
           
        }
        private Ping pingSender = new Ping();
        private string strIP = "";
        private void button1_Click(object sender, EventArgs e)
        {
            strIP = txtIP.Text;
            PingOptions pingOption = new PingOptions();
            pingOption.DontFragment = true;

            string data = "sendData:goodgoodgoodgoodgoodgood";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            PingReply reply = pingSender.Send(strIP, timeout, buffer);
            if (reply.Status == IPStatus.Success)
            {
                MessageBox.Show("能ping通 ");
            }
            else
            {
                MessageBox.Show("ping不通");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using OSSDOM.CMT.ConfigData;
using System.Net;
using System.Net.NetworkInformation;

namespace OSSDOM.CMT.CommonUse
{
    
public class PingServer
    
{
        
        
private IPEndPoint EPServer = null;
        
public PingServer()
        
{
            
try
            
{
                EPServer 
= new IPEndPoint(IPAddress.Parse(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyIP), int.Parse(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyPort));
            }

            
catch (Exception ex)
            
{
                MessageBox.Show(ex.Message 
+ " " + ex.StackTrace);
            }

        }

        
//连接
        private Ping pingSender = new Ping(); 
        
public bool ServerConnected()
        
{
            
try
            
{
                PingOptions pingOption 
= new PingOptions();
                pingOption.DontFragment 
= true;

                
string data = "sendData";
                
byte[] buffer = Encoding.ASCII.GetBytes(data);
                
int timeout = 120;
                PingReply reply 
= pingSender.Send(EPServer.Address, timeout, buffer);
                
if (reply.Status == IPStatus.Success)
                
{
                    
//MessageBox.Show("能ping通 ");
                    return true;
                }

                
else
                
{
                    
//MessageBox.Show("ping不通");
                    return false;
                }

                
                
            }

            
catch
            
{
                
return false;
            }

        }

        
//断开
        public void Disconnect()
        
{
            
        }

    }

}

posted on 2010-02-25 14:47 天书 阅读(2117) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理



<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜