C# IP地址和DNS 网络(三)
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 网络(三)的更多相关文章
- MSF魔鬼训练营-3.1.1信息收集-通过DNS和IP地址挖掘目标网络信息
情报搜集环境站渗透测试全过程的80%~90% 一.外围信息搜集(公开渠道信息搜集OSINT open source intelligence) 3.1.1信息收集-通过DNS和IP地址挖掘目标网 ...
- Windows下使用命令行设置ip地址的DNS服务器
使用命令行或者编写bat批处理设置网络连接的IP地址以及DNS服务器地址有时候会比手动更加方便,IP地址和DNS的设置一般是配合的,常用到的几个状态是: 1.IP地址动态获取,DNS也动态 2.IP地 ...
- ip地址中的网络号,主机号
当前使用的IP地址有4个字节(32bit)组成,即IPV4编码方式.每个IP地址包括两部分:网络号和主机号.当分配给主机号的二进制位越多,则能标识的主机数就越多,相应地能标识的网络数就越少,反之同理. ...
- Debian静态IP地址和DNS
Debian静态IP地址和DNS 一.配置文件及路径 /etc/network/interfaces 二.IP地址1. DHCP的IP配置如下 # The primary network interf ...
- android开发工具类之获得WIFI IP地址或者手机网络IP
有的时候我们需要获得WIFI的IP地址获得手机网络的IP地址,这是一个工具类,专门解决这个问题,这里需要两个权限: <uses-permission android:name="and ...
- linux c++ curl 根据IP地址获得当前网络的所在的地理位置
注意: 可能每个电脑的默认中文编码格式不同,有时会出现乱码,需要对返回内容进行编码转换,或者换成可指定编码格式的接口.如 搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/c ...
- linux 虚拟机设置好固定ip 修改了 dns 网络需要设置成桥接模式
linux 虚拟机设置好固定ip 修改了 dns 网络需要设置成桥接模式 可以修复网络连接(浏览器返回 server not found)
- Linux下修改主机IP地址、DNS、主机名的三种方法
使用root用户登录进入linux,打开进去终端 在终端中输入:vi /etc/sysconfig/network-scripts/ifcfg-eth0 (最后的eth0是网卡名,我的是Auto_et ...
- IP 地址 与 DNS
IP地址转化 192.168.10.1 十进制,点分十进制地址 32位二进制数字序列,四段,八位 十进制与二进制转换00000000 = 000000001 = 2 * 0 = 100000010 = ...
随机推荐
- Python基础总结之初步认识---class类(中)。第十四天开始(新手可相互督促)
昨天简单的认识类怎么定义,什么是类,类如何调用.今天的笔记会大概补充一些内容,明天的笔记会细致讲解,加深个印象即可 今天我们在了解下:类的属性,类属性属于类也属于实例化对象.也就是说类的实例化对象可以 ...
- 【AtCoder】ARC068
ARC 068 C - X: Yet Another Die Game 显然最多的就是一次6一次5 最后剩下的可能需要多用一次6或者6和5都用上 #include <bits/stdc++.h& ...
- 如何使用RedisTemplate访问Redis数据结构之Hash
Redis的Hash数据机构 Redis的散列可以让用户将多个键值对存储到一个Redis键里面. public interface HashOperations<H,HK,HV> Hash ...
- ffmpeg解码音视频过程(附代码)
0. 引言 最近一直在使用和学习ffmpeg. 工作中需要拉流解码, 获取音频和视频数据. 这些都是使用ffmpeg处理. 因为对ffmpeg接触不多, 用的不深, 在使用的过程中经常遇到不太懂的地方 ...
- tomcat 发布的web项目不在webapps目录下
双击服务器(如果服务器再启动,请停止并删除里面的项目,再clean一下), server location 选择use tomcat installation: deploy path 改为webap ...
- pthread_cond_t
条件锁pthread_cond_t (1)pthread_cond_wait的使用 等待线程1. 使用pthread_cond_wait前要先加锁2. pthread_cond_wait内部会解锁,然 ...
- 《深入理解 Java 虚拟机》学习 -- 类加载机制
<深入理解 Java 虚拟机>学习 -- 类加载机制 1. 概述 虚拟机把描述类的数据从 Class 文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的 J ...
- 关于vue项目的文件组织
最近参与了好几个项目,都是以vue-cli脚手架生成的项目,参与完成之后,有点关于项目文件组织的看法,很想聊聊. 关于目录 由vue-cli脚手架生成的项目,都会生成一个基本的目录格式. 类似于这种, ...
- mac 下 vscode配置SFTP连接
VScode中使用SFTP插件连接远程服务器进行文件修改 下载SFTP插件后,使用Ctrl+Shift+P.输入SFTP,选择第一个将会生成简短的默认配置文件 然后把sftp.json文件内内容换成以 ...
- java怎么解除文件占用(Dom4j操作完xml后怎么关流)
一.背景 项目中要解析xml,由于Dom4j的诸多优点,我就用Dom4j解析xml,代码如下: public void readXML() { SAXReader reader = new SAXRe ...