【问题标题】:Error in UDP flooder program C#UDP洪水程序C#中的错误
【发布时间】:2012-06-30 14:58:46
【问题描述】:

当我运行程序时,我得到一个无效的 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 地址。

【问题讨论】:

  • 此代码具有硬编码值"URL"IP。它不起作用是不是很奇怪?
  • 几分钟前你刚刚发布了一个非常相似的问题:stackoverflow.com/questions/11274827/…
  • 我刚刚快速浏览了您的帐户,您似乎今天刚刚注册,并就这种完全相同的方法提出了 3 个问题。我建议你组织你的想法并系统地处理这个问题。其他答案没有string IP = "URL";,这意味着您没有在这里接受其他人的建议。

标签: c# asp.net .net windows visual-studio-2010


【解决方案1】:

可能是这条线吗?

string IP = "URL";

您不需要能够动态注入 IP 地址吗?

它应该看起来像这样......

string IP = txtIPAddress.Text;

【讨论】:

    【解决方案2】:

    IP 必须是点分十进制表示法 (IPv4) 或冒号十六进制表示法 (IPv6) 的字符串

    例子:

    127.0.0.1

    ::1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-26
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      相关资源
      最近更新 更多