各位大侠们帮忙找一下错误,是一个连续IP地址端口扫描程序
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.Sockets;
using System.IO;
using System.Threading;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
int a, b, c, d;
string ipString;
int port=80;
private void button1_Click(object sender, EventArgs e)
{
for(a=192;a <=192;a++)
{
for(b=168;b <=168;b++)
{
for(c=0;c <=0;c++)
{
for(d=1;d <=2;d++)
{
ipString=a.ToString()+ ". "+b.ToString()+ ". "+c.ToString()+ ". "+d.ToString();
Thread thread = new Thread(new ThreadStart(scan));
thread.Start();
}
}
}
}
}
public void scan()
{
IPAddress ipaddress = IPAddress.Parse(ipString);
MessageBox.Show( "正在扫描IP地址为 " + ipString + "的机器 ");
TcpClient tc = new TcpClient();
tc.SendTimeout = tc.ReceiveTimeout = 2000;
try
{
tc.Connect(ipaddress, port);
if (tc.Connected)
{
richTextBox1.AppendText(ipString);
}
}
catch
{
}
finally
{
tc.Close();
tc = null;
}
}
}
}
[解决办法]
2000; 改一改
[解决办法]
兄弟
if (client.Connected)
能通过吗?