当我运行程序时,我得到一个无效的 IP 地址错误。我正在尝试使用它,以便用户可以在文本框中输入 IP 地址并使用它来发送 UDP 数据包。我不知道代码有什么问题:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using System.IO;
namespace ProjectTakedown
{
public partial class Form1 : Form
{
public Form1() //where the IP should be entered
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e) //button to start takedown
{
byte[] packetData = System.Text.ASCIIEncoding.ASCII.GetBytes("<Packet OF Data Here>");
string IP = "URL";
int port = 80;
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(IP), port);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
client.SendTo(packetData, ep);
}
private void Stop_Click(object sender, EventArgs e)
{
}
private void URL_TextChanged(object sender, EventArgs e)
{
}
}
}
不知何故,它没有读取 IP 地址。