TCP SYN扫描

 public bool isPortOpen(string ip, int port)
        {
            try
            {
                TcpClient client = new TcpClient();//创建一个TcpClient实例 
                IPAddress address = IPAddress.Parse(ip);//转化string类型的IP地址到IPAddress 
                client.Connect(address, port);//连接服务器address的port端口 
                client.Close();//连接成功立即断开 
                return true;//返回true,连接成功 
            }
            catch (Exception e)//连接失败TcpClient类抛出异常,这里捕获 
            {
                return false;//返回false,连接失败 
            }
        }

你可能感兴趣的:(TCP SYN扫描)