2025年ip地址换算十进制(ip地址十进制转二进制算法)

ip地址换算十进制(ip地址十进制转二进制算法)using System using System Collections Generic using System ComponentMod using System Data using System Drawing using System Text using System Windows Forms using System Text

大家好,我是讯享网,很高兴认识大家。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Data.OleDb; using System.Net.Sockets;

namespace biztool {


讯享网

public partial class ip : Form { public ip() { InitializeComponent(); } private void button_查询_Click(object sender, EventArgs e) { string regex = @"^d{1,3}[.]d{1,3}[.]d{1,3}[.]d{1,3}$"; Code code = new Code(); if ("".Equals(this.textBox_ip.Text)) { MessageBox.Show("请输入你所要查询的IP地址"); } else if (Regex.IsMatch(this.textBox_ip.Text, regex)) { string sql = ""; OleDbConnection conn = null; OleDbCommand command = null; OleDbDataReader reader = null; string dbfile = "biz_tools.mdb"; string connstr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source="; string userpwd = ";Jet OLEDB:Database Password=;Persist Security Info=False;"; conn = new OleDbConnection(connstr + Application.StartupPath + "\" + dbfile + userpwd); conn.Open(); //string text = "select country from ip where "; //command = new OleDbCommand(text, conn); //reader = command.ExecuteReader(); long ipLong = 0; long sumAdd = 0; //while (reader.Read()) //{ string[] ipaddr = this.textBox_ip.Text.Split('.'); long[] temp = new long[4]; for (int i = 0; i <= 3; i++) { //转换IP地址 ipLong = Convert.ToInt64(ipaddr[i]) * Convert.ToInt64(Math.Pow(256, (3 - i))); temp[i] = ipLong; } for (int j = 0; j < temp.Length; j++) { sumAdd += temp[j]; } //sql = @"update ip set startid = " + sumAdd + " where startip = '" + reader[0].ToString() + "'"; sql = "select country from ip where " + sumAdd + " between startid and endid "; command = new OleDbCommand(sql, conn); reader = command.ExecuteReader(); if (reader.Read()) { this.textBox_地址.Text = reader[0].ToString(); } else { MessageBox.Show("error"); } //sumAdd = 0; //} } else { MessageBox.Show("请输入正确的IP地址,例如:*.*.*.*"); this.textBox_ip.Text = ""; this.textBox_地址.Text = ""; } } private void button_返回_Click(object sender, EventArgs e) { this.Close(); } private void ip_FormClosing(object sender, FormClosingEventArgs e) { Form1 f = new Form1(); f.Visible = true; } } 

讯享网

}

小讯
上一篇 2025-05-17 08:25
下一篇 2025-06-08 07:22

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/144807.html