正确代码using System;
using System.Net;
namespace DNSTest
{ public class DNSUtility
{
public static int Main(string[] args)
{
String strHostName;
if (args.Length==0)
{
//获得本地的IP地址
//首先获得本地机的主机名
strHostName=Dns.GetHostName();
Console.WriteLine("本地机的主机名为:"+strHostName);
}
else
{
strHostName=args[0];
} //接着使用主机名获取IP地址列表
//一台主机可能不只一个IP
IPHostEntry ipEntry=Dns.GetHostByName(strHostName);
IPAddress[] addr=ipEntry.AddressList;
for (int i=0;i<addr.Length;i++)
{
Console.WriteLine("IP Address {0}:{1}",i,addr[i].ToString());
}
return 0;
}
}
}运行通过。
using System.Net;
namespace DNSTest
{ public class DNSUtility
{
public static int Main(string[] args)
{
String strHostName;
if (args.Length==0)
{
//获得本地的IP地址
//首先获得本地机的主机名
strHostName=Dns.GetHostName();
Console.WriteLine("本地机的主机名为:"+strHostName);
}
else
{
strHostName=args[0];
} //接着使用主机名获取IP地址列表
//一台主机可能不只一个IP
IPHostEntry ipEntry=Dns.GetHostByName(strHostName);
IPAddress[] addr=ipEntry.AddressList;
for (int i=0;i<addr.Length;i++)
{
Console.WriteLine("IP Address {0}:{1}",i,addr[i].ToString());
}
return 0;
}
}
}运行通过。
解决方案 »
- Windows2008+IIS7+C#程序发布,程序中调用VC编写dll时异常。
- 按钮实现Panel的左右移动,求大神帮忙看一下
- 有关timer,线程的lock问题【求教】
- 100分求解:C#写一个函数用来判断excel表中是否存在某个工作薄
- Gridview 显示问题
- 2005中怎麼向Image添加圖片?
- tabControl 控件不能隐藏一个tabpage,如何解决啊?
- 晕,实在是想不出错在哪
- 高分征求 管理工具-计算机管理-服务和应用程序-索引服务 中创建编目的代码或思路(包括税索引服务和编目的一些属性设置)
- how to write this piece of code in C#? urgent!!!
- 假如有两个窗体,如何显示子窗体。但不是在第一个窗体容器内显示,我想让第二个窗体像对话框一样弹出来显示
- 不能在Visual C#中创建Web应用程序,一定给分
String strHostName=new String("");//改为string strHostName;
bate1为DNS,bate2为Dns
DNS->Dns
using System;
using System.Net;
class proxy_set{
public void proxyHost(string s_host){
WebProxy proxyObject = new WebProxy("http://10.127.0.1:80/",true);
Uri siteUri = new Uri(s_host);
if (proxyObject.IsBypassed(siteUri)){
Console.WriteLine("This is LocalIPAddress , do not use proxy!");
//WebRequest req = WebRequest.Create(siteUri);
//req.Proxy=proxyObject;
}
else{
Console.WriteLine("This is not LocalIPAddress , do use proxy!");
}//if
}
}//class end
//=========================================================================
class ResolveDNS{
IPAddress[] m_arrayIPs;
public void Resolve(string s_host){
IPHostEntry ip=Dns.GetHostByName(s_host);
m_arrayIPs=ip.AddressList;
}
//indexer
public IPAddress this[int nindex]{
get{
return m_arrayIPs[nindex];
}
}
//indexer end
//-------------------------------
//progerty
public int IPLength{
get{
return m_arrayIPs.Length;
}
}
//progerty end
}
//class end
//==============================================================================
class testAPP{
public static void Main(string[] args){
proxy_set proxy_1=new proxy_set();
ResolveDNS resolve1=new ResolveDNS();
//======================================================
try{
proxy_1.proxyHost("http://"+args[0]);
resolve1.Resolve(args[0]);
int n=resolve1.IPLength;
Console.WriteLine("Get IP address .");
Console.WriteLine();
for(int i=0;i<n;i++){
Console.WriteLine(resolve1[i]);
}
}//try
catch(Exception e){
Console.WriteLine("Finding a Wrong :{0}",e.Message);
Console.WriteLine("Stoping ......!");
}
//=======================================================
}
}
/*
* Get HostName by IP , or IP by HostName
* Input parameter one: IP
* Host
* Output parameter two: HostName
* IP Address
*/
using System;
using System.Net;
class IP_set{
string s_hostname;
public void host_name(string ip){
IPAddress myip=IPAddress.Parse(ip);
IPHostEntry myhost=Dns.GetHostByAddress(myip);
s_hostname=myhost.HostName;
}
public string get_name{
get{
return s_hostname;
}
}
}//class end
//=======================================================
class Host_set{
IPAddress[] m_arrayIPs;
public void Resolve(string s_host){
IPHostEntry ip=Dns.GetHostByName(s_host);
m_arrayIPs=ip.AddressList;
}
//indexer
public IPAddress this[int nindex]{
get{
return m_arrayIPs[nindex];
}
}
//indexer end
//-------------------------------
//progerty
public int IPLength{
get{
return m_arrayIPs.Length;
}
}
//progerty end
}
//class end
//============================================================class Test{
public static void Main(string[] args){
string condition;
condition=args[0];
try{
switch (condition){
case "IP":
case "ip":
IP_set my_Host=new IP_set();
try{
my_Host.host_name(args[1]);
Console.WriteLine("Alias of the IP Address ----->{0}",my_Host.get_name);
}
catch(Exception e){
Console.WriteLine("Finding Wrong is :{0}",e.Message);
Console.WriteLine("Now , Stoping......");
}
break;
case "host":
case "Host":
Host_set resolve1=new Host_set();
//proxy_set proxy_1=new proxy_set();
//======================================================
try{
//proxy_1.proxyHost("http://"+args[0]);
resolve1.Resolve(args[1]);
int n=resolve1.IPLength;
Console.WriteLine("Get IP address .");
Console.Write("your IP Address----->");
for(int i=0;i<n;i++){
Console.WriteLine(resolve1[i]);
}
}//try
catch(Exception e){
Console.WriteLine("Finding Wrong is :{0}",e.Message);
Console.WriteLine("Now ,Stoping ......!");
}
break;
}//switch
}//try
catch(Exception e1){Console.WriteLine("Error one is :{0}",e1.Message);
}//catch
}
}