如何从本地计算机名称中查找计算机的IP地址 [英] Howto find the IP address of a machine from it's local machine name
本文介绍了如何从本地计算机名称中查找计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我已经进行了很多冲浪,但是找不到.
我想连接到WCF服务,但是我拥有它的机器名称(例如"DESK2"),而不是DNS名称.
Hello
I''ve been doing a lot of surfing but couldn''t find this out.
I want to connect to a WCF service but I have it''s machine name (eg "DESK2"), rather than a DNS name.
Uri uri = new Uri("http://localhost:8000/ServiceModelSamples/CalcService/CalculatorService");
EndpointAddress adrs = new EndpointAddress(uri);
CalculatorClient client = new CalculatorClient("WSHttpBinding_ICalculator", adrs);
有什么想法吗?
非常感谢
Ronny
Any ideas?
Many thanks
Ronny
推荐答案
ronzu,
你可以尝试
我希望它能正常工作.
IPAddress myIP = IPAddress.Parse(Request.UserHostName);
IPHostEntry GetIPHost = Dns.GetHostEntry(Request.UserHostName);
Response.Write(GetIPHost.HostName);
Hi ronzu,
you can try it
I hope it''s working fine.
IPAddress myIP = IPAddress.Parse(Request.UserHostName);
IPHostEntry GetIPHost = Dns.GetHostEntry(Request.UserHostName);
Response.Write(GetIPHost.HostName);
感谢bojjaiah ...但它似乎没有用.
文档中的IPAddress.Parse仅接受:
一个字符串,其中包含一个IP地址(对于IPv4为点分四进制表示法,对于IPv6为冒号十六进制表示法).
无论如何,当我给它一个机器名("DESK2")时,它就会想到FormatException.
我在另一个站点上找到了解决方案.
URI字符串确实接受机器名称:
Uri uri =新的Uri("http://DESK2:8000/ServiceModelSamples/CalcService/CalculatorService");
有时,最简单的方法实际上有效!
干杯
罗尼
Thanks bojjaiah... but it didn''t seem to work.
IPAddress.Parse from the documentation only accepts:
A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
In any case it came up with FormatException when I just gave it a machine name ("DESK2").
I got the solution on another site.
The URI string does accept a machine name:
Uri uri = new Uri("http://DESK2:8000/ServiceModelSamples/CalcService/CalculatorService");
Sometimes the simplest thing actually works!
Cheers
Ronny
这篇关于如何从本地计算机名称中查找计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文