C# IP地址和DNS 网络(三)

 1             Uri i = new Uri("http://www.baidu.com");   //可获取属性
 2
 3             UriBuilder u = new UriBuilder("http://www.baidu.com");  //可获取、设置属性
 4
 5             IPAddress ipAddress = IPAddress.Parse("192.168.31.34");  //ip地址转换
 6             byte[] address = ipAddress.GetAddressBytes();
 7             string ipString = ipAddress.ToString();
 8
 9             IPHostEntry host = Dns.Resolve("www.baidu.com"); //获取IPHostEntry对象
10             IPHostEntry whost = Dns.GetHostByAddress("192.168.31.114");

根据域名、地址,查询主机信息

Form

 1 public partial class Form1 : Form
 2     {
 3         public Form1()
 4         {
 5             InitializeComponent();
 6         }
 7
 8         private void button1_Click(object sender, EventArgs e)
 9         {
10             try
11             {
12                 IPHostEntry iphost = Dns.GetHostEntry(textBox1.Text);
13                 foreach(var ip in iphost.AddressList)
14                 {
15                     string ipaddress = ip.AddressFamily.ToString();
16                     listBox1.Items.Add(ipaddress);
17                     listBox1.Items.Add("  " + ip.ToString());
18                 }
19                 textBox2.Text = iphost.HostName;
20
21
22             }
23             catch (Exception ex)
24             {
25                 MessageBox.Show("Unable to process  the request because the following problem occurred:\n" + ex.Message + " Exception occurred");
26
27             }
28         }
29     }

Designer

  1    partial class Form1
  2     {
  3         /// <summary>
  4         /// Required designer variable.
  5         /// </summary>
  6         private System.ComponentModel.IContainer components = null;
  7
  8         /// <summary>
  9         /// Clean up any resources being used.
 10         /// </summary>
 11         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 12         protected override void Dispose(bool disposing)
 13         {
 14             if (disposing && (components != null))
 15             {
 16                 components.Dispose();
 17             }
 18             base.Dispose(disposing);
 19         }
 20
 21         #region Windows Form Designer generated code
 22
 23         /// <summary>
 24         /// Required method for Designer support - do not modify
 25         /// the contents of this method with the code editor.
 26         /// </summary>
 27         private void InitializeComponent()
 28         {
 29             this.label1 = new System.Windows.Forms.Label();
 30             this.button1 = new System.Windows.Forms.Button();
 31             this.textBox1 = new System.Windows.Forms.TextBox();
 32             this.textBox2 = new System.Windows.Forms.TextBox();
 33             this.label2 = new System.Windows.Forms.Label();
 34             this.label3 = new System.Windows.Forms.Label();
 35             this.listBox1 = new System.Windows.Forms.ListBox();
 36             this.SuspendLayout();
 37             //
 38             // label1
 39             //
 40             this.label1.AutoSize = true;
 41             this.label1.Location = new System.Drawing.Point(12, 18);
 42             this.label1.Name = "label1";
 43             this.label1.Size = new System.Drawing.Size(281, 12);
 44             this.label1.TabIndex = 0;
 45             this.label1.Text = "Enter name to resolve and click Resolve button";
 46             //
 47             // button1
 48             //
 49             this.button1.Location = new System.Drawing.Point(259, 30);
 50             this.button1.Name = "button1";
 51             this.button1.Size = new System.Drawing.Size(75, 21);
 52             this.button1.TabIndex = 1;
 53             this.button1.Text = "Resolve";
 54             this.button1.UseVisualStyleBackColor = true;
 55             this.button1.Click += new System.EventHandler(this.button1_Click);
 56             //
 57             // textBox1
 58             //
 59             this.textBox1.Location = new System.Drawing.Point(15, 33);
 60             this.textBox1.Name = "textBox1";
 61             this.textBox1.Size = new System.Drawing.Size(228, 21);
 62             this.textBox1.TabIndex = 2;
 63             //
 64             // textBox2
 65             //
 66             this.textBox2.Location = new System.Drawing.Point(15, 76);
 67             this.textBox2.Name = "textBox2";
 68             this.textBox2.Size = new System.Drawing.Size(228, 21);
 69             this.textBox2.TabIndex = 3;
 70             //
 71             // label2
 72             //
 73             this.label2.AutoSize = true;
 74             this.label2.Location = new System.Drawing.Point(12, 61);
 75             this.label2.Name = "label2";
 76             this.label2.Size = new System.Drawing.Size(53, 12);
 77             this.label2.TabIndex = 4;
 78             this.label2.Text = "HostName";
 79             //
 80             // label3
 81             //
 82             this.label3.AutoSize = true;
 83             this.label3.Location = new System.Drawing.Point(12, 108);
 84             this.label3.Name = "label3";
 85             this.label3.Size = new System.Drawing.Size(77, 12);
 86             this.label3.TabIndex = 5;
 87             this.label3.Text = "IP Addresses";
 88             //
 89             // listBox1
 90             //
 91             this.listBox1.FormattingEnabled = true;
 92             this.listBox1.ItemHeight = 12;
 93             this.listBox1.Location = new System.Drawing.Point(15, 123);
 94             this.listBox1.Name = "listBox1";
 95             this.listBox1.Size = new System.Drawing.Size(217, 160);
 96             this.listBox1.TabIndex = 6;
 97             //
 98             // Form1
 99             //
100             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
101             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
102             this.ClientSize = new System.Drawing.Size(346, 333);
103             this.Controls.Add(this.listBox1);
104             this.Controls.Add(this.label3);
105             this.Controls.Add(this.label2);
106             this.Controls.Add(this.textBox2);
107             this.Controls.Add(this.textBox1);
108             this.Controls.Add(this.button1);
109             this.Controls.Add(this.label1);
110             this.Name = "Form1";
111             this.Text = "Form1";
112             this.ResumeLayout(false);
113             this.PerformLayout();
114
115         }
116
117         #endregion
118
119         private System.Windows.Forms.Label label1;
120         private System.Windows.Forms.Button button1;
121         private System.Windows.Forms.TextBox textBox1;
122         private System.Windows.Forms.TextBox textBox2;
123         private System.Windows.Forms.Label label2;
124         private System.Windows.Forms.Label label3;
125         private System.Windows.Forms.ListBox listBox1;
126     }

时间: 2025-01-06 16:05:27

C# IP地址和DNS 网络(三)的相关文章

MSF魔鬼训练营-3.1.1信息收集-通过DNS和IP地址挖掘目标网络信息

情报搜集环境站渗透测试全过程的80%~90% 一.外围信息搜集(公开渠道信息搜集OSINT  open source intelligence) 3.1.1信息收集-通过DNS和IP地址挖掘目标网络信息 1.whois域名注册信息查询 whois查询时去掉www.ftp等前缀 2.nslookup与dig域名查询 nslookup与dig的区别 nslookup只会得到DNS解析服务器报错在Cache中的非权威解答. dig工具可以从该域名的官方DNS服务器商查询到精确的权威答案.?尝试查询了一

centos7的ip地址.网关,DNS设置和服务的控制

centos7的网络设置和服务控制 需求和目的:1.学会正确配置rhel7的网络连接                         2.熟悉明确rhel7的服务控制由什么来管制                         3.能熟练的掌握网络的连通性测试             实现的效果:能熟悉rhel7的网络配置和服务,控制             理论知识点的描述:1.rhel7和rhel6以前的版本很多的配置文件都发生变化,尤其是ip地址编号格式,展现在我们眼前的rhel7的命名更

ip地址中的网络号,主机号

当前使用的IP地址有4个字节(32bit)组成,即IPV4编码方式.每个IP地址包括两部分:网络号和主机号.当分配给主机号的二进制位越多,则能标识的主机数就越多,相应地能标识的网络数就越少,反之同理. ip地址中的网络号,主机号有什么作用? 打个很简单的比喻:网卡的MAC地址就像你身份证上的身份证号码,虽然是唯一的,但是寻址起来很麻烦:而IP地址就像你的家庭详细地址,楼上说的对:每个IP地址都是由两部分构成:网络号,主机号.其中,网络号标识某个网络,主机号标识在该网络上的一个特定的主机.这样就形

使用批处理命令设置windows系统的ip地址和dns

ASP.NET MVC路由(一) 前言 从这一章开始,我们即将进入MVC的世界,在学习MVC的过程中在网上搜索了一下,资料还是蛮多的,只不过对于我这样的初学者来看还是有点难度,自己就想看到有一篇引导性的资料可以帮助我初步的了解一下这部分知识,然后再去学习大神们写的资料.并不是说看完文章就会可以开发.可以怎么怎么样,没有!这些都没有,只是让你在脑海中把这部分内容记住它们的模型图以及一个大概的在MVC框架中的位置或者是整个系统中的位置,说了这么多的目的就是让大家更好的了解基础知识,有了它以后的进阶会

网址(url),域名,ip地址,dns,hosts之间的关系

什么是ip? 我们知道,在Internet上有千百万台主机,为了区分这些主机,人们给每台主机都分配了一个专门的地址,称为IP地址.通过IP地址就可以访问到每一台主机. IP地址由4部分数字组成,每部分都不大于256,各部分之间用小数点分开.例如"百度搜索"主机的IP地址就是:"119.75.217.109,"在浏览器上输入这个IP地址,就可以访问到百度的主页. 我们的每个虚拟主机用户,都分配一个永久的IP地址. 什么是域名? 虽然可以通过IP地址来访问每一台主机,但

ubuntu16.0.4 设置固定ip地址和dns

因为的公司的电脑每次开机重启时分配的IP地址都不一样,这导致的很多不方便的事情,所以干脆锁定一个固定的IP地址,下面就是我锁定IP地址的步骤: 1.设置ip地址 vi /etc/network/interfaces 添加如下内容: # The primary network interface # enp2s0是你电脑的网卡,不知道自己是什么样的网卡,可以通过命令ifconfig查看 auto enp2s0 iface enp2s0 inet static # 192.168.2.83是你要固定

Linux CentOS 7 IP地址配置及网络问题排查

一.Linux CentOS 7 IP地址配置 输入命令"ifconfig" 查看本机IP地址. [[email protected] ~]# ifconfig     ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500         inet 192.168.42.170  netmask 255.255.255.0  broadcast     192.168.42.255         ether

kali ip地址和dns配置

临时修改ip地址 ifconfig eth0 up              //端口启用 ifconfig eth0 down            //端口关闭 ifconfig eth0 192.168.1.10    //只修改ip地址 ifconfig eth0 192.168.1.10/24 或者 ifconfig eth0 1.1.1.1 netmask 255.0.0.0                               //修改ip地址和掩码 临时修改网关 route

路由器、交换机学习之IP地址、使用网络掩码划分子网

局域网子网划分 对于C类IP地址来说(192.168.1.X,其中前面的192.168.1为网络号,后面的X为主机号,这样的网络中可以有254台主机,其中.0为局域网地址,.255为广播地址)进行子网划分意味着把254个可用主机按照需求划分为多个局域网,每个局域网有若干个主机组成. 子网掩码 十进制 CIDR 00000000 0 /24 10000000 128 /25 11000000 192 /26 11100000 224 /27 11110000 240 /28 11111000 24