1
所以我正在做一個UDP數據包發送者,但我有一個問題。我設置了它,當用戶點擊「按鈕2」時,它們會自動發送一個數據包到我指定的IP地址。我該如何做到這一點,以便用戶可以在那裏放置自己的IP地址,併成爲數據包發送到的IP?這裏是我到目前爲止的代碼:如何爲UDP數據包發送者啓用自定義IP地址?
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 = "127.0.0.1";
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)
{
}
}
}
另外如何獲得停止按鈕來停止該過程?
嗯, 「ProjectTakedown」? –