Uri i = new Uri("http://www.baidu.com");   //可获取属性

             UriBuilder u = new UriBuilder("http://www.baidu.com");  //可获取、设置属性

             IPAddress ipAddress = IPAddress.Parse("192.168.31.34");  //ip地址转换
byte[] address = ipAddress.GetAddressBytes();
string ipString = ipAddress.ToString(); IPHostEntry host = Dns.Resolve("www.baidu.com"); //获取IPHostEntry对象
IPHostEntry whost = Dns.GetHostByAddress("192.168.31.114");

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

Form

 public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
try
{
IPHostEntry iphost = Dns.GetHostEntry(textBox1.Text);
foreach(var ip in iphost.AddressList)
{
string ipaddress = ip.AddressFamily.ToString();
listBox1.Items.Add(ipaddress);
listBox1.Items.Add(" " + ip.ToString());
}
textBox2.Text = iphost.HostName; }
catch (Exception ex)
{
MessageBox.Show("Unable to process the request because the following problem occurred:\n" + ex.Message + " Exception occurred"); }
}
}

Designer

    partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "Enter name to resolve and click Resolve button";
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "Resolve";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(, );
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(, );
this.textBox1.TabIndex = ;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(, );
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(, );
this.textBox2.TabIndex = ;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
this.label2.Text = "HostName";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
this.label3.Text = "IP Addresses";
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = ;
this.listBox1.Location = new System.Drawing.Point(, );
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(, );
this.listBox1.TabIndex = ;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ListBox listBox1;
}

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

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

    情报搜集环境站渗透测试全过程的80%~90%   一.外围信息搜集(公开渠道信息搜集OSINT  open source intelligence) 3.1.1信息收集-通过DNS和IP地址挖掘目标网 ...

  2. Windows下使用命令行设置ip地址的DNS服务器

    使用命令行或者编写bat批处理设置网络连接的IP地址以及DNS服务器地址有时候会比手动更加方便,IP地址和DNS的设置一般是配合的,常用到的几个状态是: 1.IP地址动态获取,DNS也动态 2.IP地 ...

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

    当前使用的IP地址有4个字节(32bit)组成,即IPV4编码方式.每个IP地址包括两部分:网络号和主机号.当分配给主机号的二进制位越多,则能标识的主机数就越多,相应地能标识的网络数就越少,反之同理. ...

  4. Debian静态IP地址和DNS

    Debian静态IP地址和DNS 一.配置文件及路径 /etc/network/interfaces 二.IP地址1. DHCP的IP配置如下 # The primary network interf ...

  5. android开发工具类之获得WIFI IP地址或者手机网络IP

    有的时候我们需要获得WIFI的IP地址获得手机网络的IP地址,这是一个工具类,专门解决这个问题,这里需要两个权限: <uses-permission android:name="and ...

  6. linux c++ curl 根据IP地址获得当前网络的所在的地理位置

    注意: 可能每个电脑的默认中文编码格式不同,有时会出现乱码,需要对返回内容进行编码转换,或者换成可指定编码格式的接口.如  搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/c ...

  7. linux 虚拟机设置好固定ip 修改了 dns 网络需要设置成桥接模式

    linux  虚拟机设置好固定ip 修改了 dns  网络需要设置成桥接模式  可以修复网络连接(浏览器返回 server not  found)

  8. Linux下修改主机IP地址、DNS、主机名的三种方法

    使用root用户登录进入linux,打开进去终端 在终端中输入:vi /etc/sysconfig/network-scripts/ifcfg-eth0 (最后的eth0是网卡名,我的是Auto_et ...

  9. IP 地址 与 DNS

    IP地址转化 192.168.10.1 十进制,点分十进制地址 32位二进制数字序列,四段,八位 十进制与二进制转换00000000 = 000000001 = 2 * 0 = 100000010 = ...

随机推荐

  1. Java包的基本概述

    第七章 7.1 包的基本概述 起因: 在我们设计一个程序的时候(尤其是多人合作),会写一些类来实现功能,但是往往会有重名的现象发生,为了解决这个问题,则专门设计了包.(还有其他作用,下述) 简单理解: ...

  2. Oracle快速运行一指禅

      对于oracle数据库下的企业级应用开发,经常会使用到新建用户,新建表空间以及数据的迁移工作.虽然目前互联网存在很多单个问题的解决方案,但是比较零散,本博文结合研发兄弟们的实际现状,提供一套完整初 ...

  3. win10现在安装redis

    一.下载: 下载地址: https://github.com/MicrosoftArchive/redis/releases 根据系统下载的版本:以(64位为例) 下载后一般解压到根目录下:如(E:\ ...

  4. 【51nod】2591 最终讨伐

    [51nod]2591 最终讨伐 敲51nod是啥评测机啊,好几次都编译超时然后同一份代码莫名奇妙在众多0ms中忽然超时 这道题很简单就是\(M\)名既被诅咒也有石头的人,要么就把石头给没有石头被诅咒 ...

  5. 数据结构 -- 栈(Stack)

    一.栈的简介 定义 栈(英语:stack)又称为堆栈或堆叠,栈作为一种数据结构,它按照先进后出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要读数据的时候从栈顶开始弹出数据(最后一个数据 ...

  6. 2019牛客暑期多校训练营(第三场)F Planting Trees 单调队列

    F Planting Trees 题目链接 https://ac.nowcoder.com/acm/contest/883/F 题目描述 The semester is finally over an ...

  7. DEDE调用列表页,前台titlelen显示不全问题解决

    一. 问题描述:{dede:list titlelen='100'}标题长度设为100后,但前台调用显示最长却只有60. 二. 产生原因:经过我多度查找,最终导致标题显示不全的原因是在DEDE生数据库 ...

  8. Jmeter之JSON Path Extractor的使用(JSON-handle下载安装和使用)

    jp@gc - JSON Path Extractor和“正则表达式提取器”使用效果一样. 他的作用单一,只提取json数据 jp@gc - JSON Path Extracto 变量名自己定义,js ...

  9. 怎样退出mysql命令行

    使用: mysql -u root -p 进入 mysql 命令号以后, 如果想退出, 可以使用: quit 命令, 如下: mysql -u root -p quit;

  10. 面试之HTML5 Web存储

    前几天面试遇到了一个题是问localStorage和sessionStorage的区别,当时的回答不是很全面,今天就针对这个问题做一下整理(概念,用法,区别) HTML5 Web存储,一个比 cook ...