Hi,
I use the code below to get the IP of computer:
My computer has only one ip: 192.168.0.100,
But there are tree IPs get by GetHostEntry:
192.168.0.100
192.168.0.1
192.168.122.1
Why?
//--------------------------------------------------------------------------------------
IPHostEntry ipEntry = Dns.GetHostEntr y(strHostName);
IPAddress[] addr = ipEntry.Address List; 3 6967
When you call GetHostEntry, it returns the IP addresses that are mapped
to that DNS name, not necessarily the IP addresses a local machine has.
A better way to get this information (which doesn't rely on entries in
the DNS table) would be to use the classes in the System.Manageme nt
namespace to query all the network adapters on your machine for the
instances of the Win32_NetworkAd apterConfigurat ion WMI class. Then, you can
access the IPAddresses property on the instances to get the ip addresses
that are allocated to each network adapter.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:uo******** ******@TK2MSFTN GP14.phx.gbl... Hi, I use the code below to get the IP of computer: My computer has only one ip: 192.168.0.100, But there are tree IPs get by GetHostEntry: 192.168.0.100 192.168.0.1 192.168.122.1
Why?
//-------------------------------------------------------------------------------------- IPHostEntry ipEntry = Dns.GetHostEntr y(strHostName); IPAddress[] addr = ipEntry.Address List;
Thanks,
Could you give me an example?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> ¼¶¼g©ó¶l¥ó·s»D: %2************* ***@TK2MSFTNGP1 2.phx.gbl... When you call GetHostEntry, it returns the IP addresses that are mapped to that DNS name, not necessarily the IP addresses a local machine has.
A better way to get this information (which doesn't rely on entries in the DNS table) would be to use the classes in the System.Manageme nt namespace to query all the network adapters on your machine for the instances of the Win32_NetworkAd apterConfigurat ion WMI class. Then, you can access the IPAddresses property on the instances to get the ip addresses that are allocated to each network adapter.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"ad" <fl****@wfes.tc c.edu.tw> wrote in message news:uo******** ******@TK2MSFTN GP14.phx.gbl... Hi, I use the code below to get the IP of computer: My computer has only one ip: 192.168.0.100, But there are tree IPs get by GetHostEntry: 192.168.0.100 192.168.0.1 192.168.122.1
Why?
//-------------------------------------------------------------------------------------- IPHostEntry ipEntry = Dns.GetHostEntr y(strHostName); IPAddress[] addr = ipEntry.Address List;
using System;
using System.Manageme nt;
using System.Runtime. InteropServices ;
using System.Threadin g;
public class Wmis {
public static void Main()
{
// query only IP enabled Adapters
using(Managemen tObjectSearcher query = new
ManagementObjec tSearcher("SELE CT * FROM Win32_NetworkAd apterConfigurat ion
"))
{
ManagementObjec tCollection queryCollection = query.Get();
foreach( ManagementObjec t mo in queryCollection )
{
string[] addresses = (string[])mo["IPAddress"];
if((bool)mo["IpEnabled"]) {
foreach(string s in addresses)
Console.WriteLi ne( "IP Address '{0}'", s);
}
}
}
}
}
Willy.
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:uG******** ******@tk2msftn gp13.phx.gbl... Thanks, Could you give me an example?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> ¼¶¼g©ó¶l¥ó·s»D: %2************* ***@TK2MSFTNGP1 2.phx.gbl... When you call GetHostEntry, it returns the IP addresses that are mapped to that DNS name, not necessarily the IP addresses a local machine has.
A better way to get this information (which doesn't rely on entries in the DNS table) would be to use the classes in the System.Manageme nt namespace to query all the network adapters on your machine for the instances of the Win32_NetworkAd apterConfigurat ion WMI class. Then, you can access the IPAddresses property on the instances to get the ip addresses that are allocated to each network adapter.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"ad" <fl****@wfes.tc c.edu.tw> wrote in message news:uo******** ******@TK2MSFTN GP14.phx.gbl... Hi, I use the code below to get the IP of computer: My computer has only one ip: 192.168.0.100, But there are tree IPs get by GetHostEntry: 192.168.0.100 192.168.0.1 192.168.122.1
Why?
//-------------------------------------------------------------------------------------- IPHostEntry ipEntry = Dns.GetHostEntr y(strHostName); IPAddress[] addr = ipEntry.Address List;
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott J. Peterson, MCSD, MCPSB, MCT |
last post by:
I'm trying to emulate passing the 'SERVER' parameter in an NSLOOKUP using the
Dns namespace, but I don't see anywhere this can be set.
For example, I may do this;
IPHostEntry ipEntry = Dns.GetHostEntry(strServerIP);
....but I want to specify WHICH DNS server to resolve against, not just the
default. From a command prompt I would do NSLOOKUP, then type SERVER
|
by: css |
last post by:
When I call Directory.Exists for a UNC path like below...
if (Directory.Exists(@\\SomeServer\C) == false)
{
....
}
and that server does not exist on the connected network, it takes around a
minute to return from the call which properly returns false.
|
by: RWF |
last post by:
I am trying to do a reverse DNS lookup using Dns.GetHostEntry in .NET 2.0,
but it seems to kind of crap out when the result is an answer with multiple
records. It doesnt seem to give any type of answer.
The old Dns.GetHostByAddress seems to work partially by atleast returning 1
IpHostEntry, but it has been deprecated.
Any ideas on how to retrieve the multiple records?
example:
|
by: The Grim Reaper |
last post by:
Hi all,
I have a small "irritant" to do with DNS resolving in .NET Framework v2.0.
For this example, assume the following network information;
Local IP address is 192.168.0.10, on a PC named "PC_01"
Remote address is 192.168.0.20, on a local LAN, and named "PC_02"
DNS.GetHostByAddress("192.168.0.20").Hostname returns "PC_02"
DNS.Resolve("192.168.0.20").Hostname returns "PC_02"
|
by: The Grim Reaper |
last post by:
Hi all,
I have a small "irritant" to do with DNS resolving in .NET Framework v2.0.
For this example, assume the following network information;
Local IP address is 192.168.0.10, on a PC named "PC_01"
Remote address is 192.168.0.20, on a local LAN, and named "PC_02"
DNS.GetHostByAddress("192.168.0.20").Hostname returns "PC_02"
DNS.Resolve("192.168.0.20").Hostname returns "PC_02"
| |
by: kvnsdr |
last post by:
I can type an IP address and receive Internet domain name and my workstation
name however no other IPs of computers on our internal network will resolve
to a thier machine name only to the same IP that is entered. What's up
Microsoft????
I can say that before we switched over .NET 1.1 to 2.0 the
Dns.Resolve(entry); would find a name for any IP, LAN or WAN.
Q. Any ideas??????????
|
by: Steve Richter |
last post by:
I am using Dns.GetHostByAddress and Dns.Resolve to successfully
resolve and IP address to an IPEndPoint.
IPEndPoint ep = null;
IPAddress ipAddr = IPAddress.Parse(m_sRemoteHost);
ep = new IPEndPoint(Dns.GetHostByAddress(ipAddr).AddressList,
m_iRemotePort);
// ep = new IPEndPoint(Dns.GetHostEntry(ipAddr).AddressList,
m_iRemotePort);
// ep = new IPEndPoint(Dns.Resolve(m_sRemoteHost).AddressList,
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
I am trying to get the DNS name of an arbitrary IP address on the network.
If I use GetHostEntry as the documentation suggests I only get the name of
the machine I am running the code on. All other IP’s returns the IP in the
HostName property of the IPHostEntry object returned by GetHostEntry.
If I use Dns.GetHostByAddress or Dns.Resolve I get the name, but these are
marked as obsolete. What is the correct way to get this...
|
by: desire83 |
last post by:
hello, im new in c#.net...
i have made a server application and a client application for the same machine...the server is suppos to send a string to client when the button on the server application is pressed...but im not recieving the string on my client application
here are the codes for both the applications
SERVER:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |