谁能帮我看看这个问题。先谢了

xczhouyang 2005-02-04 02:30:21
谁能帮我写一个能把218.6.174.242
这种ip地换算成450255512一串数字的ip地址的程序
用C#写
...全文
112 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yizhixiaozhu 2005-02-04
  • 打赏
  • 举报
回复
学习
帮顶
xiongchen 2005-02-04
  • 打赏
  • 举报
回复
上在贴的代码有错误!
AllenTing 2005-02-04
  • 打赏
  • 举报
回复
MSDN IPADDRESS类看的时候再仔细点哦 .....
9494
lucbesson 2005-02-04
  • 打赏
  • 举报
回复
MSDN IPADDRESS类看的时候再仔细点哦 .....
nga96 2005-02-04
  • 打赏
  • 举报
回复
IPADDRESS类中直接有方法呀,兄弟
mobydick 2005-02-04
  • 打赏
  • 举报
回复
using System;
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Data;

namespace ConvertIp2Long
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FormMain : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public FormMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormMain));
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(40, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(152, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(40, 80);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "转换IP";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(40, 48);
this.textBox2.Name = "textBox2";
this.textBox2.ReadOnly = true;
this.textBox2.Size = new System.Drawing.Size(152, 21);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 23);
this.label1.TabIndex = 4;
this.label1.Text = "Sur";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(0, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(32, 23);
this.label2.TabIndex = 5;
this.label2.Text = "Des";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(120, 112);
this.button2.Name = "button2";
this.button2.TabIndex = 6;
this.button2.Text = "About";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// FormMain
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(202, 151);
this.Controls.Add(this.button2);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ConvertIp2Long";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormMain());
}

static string regexString = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b";
Regex regex = new Regex(regexString, RegexOptions.IgnoreCase|RegexOptions.Compiled);
private void button1_Click(object sender, System.EventArgs e)
{
string temp = textBox1.Text;
if(temp == "")
{
textBox2.Text = "请输入IP地址";
return;
}
if(regex.IsMatch(temp))
{
textBox2.Text = ConvertIp2Long(temp).ToString();
}
else
{
textBox2.Text = "非法的IP地址";
}
}

private static long ConvertIp2Long(string address)
{
try
{
string[] s1 = address.Split('.');
long ipLong = 0;
for(int i = 0; i <= 3; ++i)
{
ipLong += long.Parse(s1[i])*((long) Math.Pow(256, 3 - i));
}
return ipLong;
}
catch
{
return 0;
}
}

private void button2_Click(object sender, System.EventArgs e)
{
FormAbout fa = new FormAbout();
fa.ShowDialog(this);
}
}
}
mobydick 2005-02-04
  • 打赏
  • 举报
回复
/// <summary>
/// 转化IP地址到长整形数
/// </summary>
/// <param name="address">IP地址</param>
/// <returns>长整形数</returns>
private static long ConvertIPToLong(string address)
{
try
{
string[] s1 = address.Split('.');
long ipLong = 0;
for(int i = 0; i <= 3; ++i)
{
ipLong += long.Parse(s1[i])*((long) Math.Pow(256, 3 - i));
}
return ipLong;
}
catch
{
return 0;
}
}
mazekui 2005-02-04
  • 打赏
  • 举报
回复
up
yangxd_yi 2005-02-04
  • 打赏
  • 举报
回复
你的地址转化成字符串的算法是什么啊....
mousetrue 2005-02-04
  • 打赏
  • 举报
回复
??IPAddress.Parse()
老汉 2005-02-04
  • 打赏
  • 举报
回复
218.6.174.242和450255512的关系是?
cqzhangq 2005-02-04
  • 打赏
  • 举报
回复
UP
随机开仓,止盈1~2个点,止损1~20个点能实现盈利正期望吗?《从编程小白到量化宗师之路》系列课程是一套综合性实战课程,涵盖股票,期货,虚拟货币等的交易方法和策略手段。《m单位止盈 n单位止损的方式,能不能实现盈利?》是本系列的第四个中级课程。本网站的课程宗旨是缩短个人或小型投资者与大型机构投资者之间的的差距。课程内容从交易者经常见到,经常思考的问题开始,通过分析成交后的盈亏分布,建立模型,刻画问题,并对问题以数学的方式进行了表达。从而得出结论。与市面上的其他理论课程不同,本课程注重实战,注重结果,全部模型代码均已经上传发表,学员上课后,可以使用自己的tick数据,进行分析。如果获取tick数据有疑问,可以参考课程:《期货CTP高频数据Tick下载》 https://edu.csdn.net/course/detail/24783本课程能够解答的问题有:1)请问1单位止盈,3单位止损的系统是否能实现正期望值? https://www.zhihu.com/question/423194389/answer/14989174122)抢帽子交易是什么意思?为什么有的人能够成功,说是取款机,而有的人说风险巨大,是老虎机。看过这个课程,您将会知道:a) 这类问题的究极解决方案,直达问题核心,不再纠结原因b)构建一段时间可用的交易策略c)知道“没有不变的策略”的原因  

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧