473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

All IP addresses for a hostname

I have a host which has two NIC cards; one configured for LAN
connections, and another for external connections.

Say the ip address are
1) x.x.x.x - for LAN
2) y.y.y.y - for external

hostname = 'hichetu'

With the following code snippet...

public void TestDNS(string hostname)
{
try
{
IPHostEntry hostInfo = Dns.Resolve(hostname);
IPAddress[] address = hostInfo.AddressList;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nIP Address list :");
for(int index=0; index < address.Length; index++)
{
Console.WriteLine(address[index]);
}
}
}

....I always get
Host name : hichetu.a.b

IP Address list
x.x.x.x

Now, How do i get the other ip address y.y.y.y ?
Nov 15 '05 #1
3 3753
I'm not sure that you can do it the way you're trying to do it. I could be
wrong.

I actually just wrote code to do this last night, though, using WMI. I'm not
sure if this is the "best" way, but it seems to work. You can also do it
through unmanaged code, but I prefer to stick with managed code wherever
possible.

A few notes about the code below. The NetworkAdapter class simply stores the
IP address list, description, and MAC Address properties. You can save
whatever information you'd like. Search the MSDN for
Win32_NetworkAdapterConfiguration to see the available data. My code only
returns adapters that have IP addresses assigned to them.

My code is as follows:

public NetworkAdapterVector GetAdapterList()
{
ManagementClass mgmt = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mgmt.GetInstances();
NetworkAdapterVector adapters = new NetworkAdapterVector();

// Search for adapters with IP addresses
foreach(ManagementObject mob in moc)
{

string[] addresses = (string[])mob.Properties["IPAddress"].Value;
if (null == addresses)
{
continue;
}

NetworkAdapter na = new NetworkAdapter();
na.Description = (string) mob.Properties["Description"].Value;
na.MacAddress = (string) mob.Properties["MACAddress"].Value;
na.IPAddresses = addresses;
adapters.Add(na);
}
return adapters;
}

--
http://www.petedavis.net
"HiChetu" <go**********@gawab.com> wrote in message
news:d4**************************@posting.google.c om...
I have a host which has two NIC cards; one configured for LAN
connections, and another for external connections.

Say the ip address are
1) x.x.x.x - for LAN
2) y.y.y.y - for external

hostname = 'hichetu'

With the following code snippet...

public void TestDNS(string hostname)
{
try
{
IPHostEntry hostInfo = Dns.Resolve(hostname);
IPAddress[] address = hostInfo.AddressList;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nIP Address list :");
for(int index=0; index < address.Length; index++)
{
Console.WriteLine(address[index]);
}
}
}

...I always get
Host name : hichetu.a.b

IP Address list
x.x.x.x

Now, How do i get the other ip address y.y.y.y ?

Nov 15 '05 #2
hi Pete Davis,

First of all, thanks for your code. It provided me with more options
to get around my problem.

But, your code returns the ip addresses of the local machine on which
the code runs. I want to get the ipaddresses of any host present in my
domain.

How do i get the ipaddresses of any hosts in my domain??
-- HiChetu
"Pete Davis" <pd******@hotmail.com> wrote in message news:<90******************************@news.megane tnews.com>...
I'm not sure that you can do it the way you're trying to do it. I could be
wrong.

I actually just wrote code to do this last night, though, using WMI. I'm not
sure if this is the "best" way, but it seems to work. You can also do it
through unmanaged code, but I prefer to stick with managed code wherever
possible.

A few notes about the code below. The NetworkAdapter class simply stores the
IP address list, description, and MAC Address properties. You can save
whatever information you'd like. Search the MSDN for
Win32_NetworkAdapterConfiguration to see the available data. My code only
returns adapters that have IP addresses assigned to them.

My code is as follows:

public NetworkAdapterVector GetAdapterList()
{
ManagementClass mgmt = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mgmt.GetInstances();
NetworkAdapterVector adapters = new NetworkAdapterVector();

// Search for adapters with IP addresses
foreach(ManagementObject mob in moc)
{

string[] addresses = (string[])mob.Properties["IPAddress"].Value;
if (null == addresses)
{
continue;
}

NetworkAdapter na = new NetworkAdapter();
na.Description = (string) mob.Properties["Description"].Value;
na.MacAddress = (string) mob.Properties["MACAddress"].Value;
na.IPAddresses = addresses;
adapters.Add(na);
}
return adapters;
}

--
http://www.petedavis.net
"HiChetu" <go**********@gawab.com> wrote in message
news:d4**************************@posting.google.c om...
I have a host which has two NIC cards; one configured for LAN
connections, and another for external connections.

Say the ip address are
1) x.x.x.x - for LAN
2) y.y.y.y - for external

hostname = 'hichetu'

With the following code snippet...

public void TestDNS(string hostname)
{
try
{
IPHostEntry hostInfo = Dns.Resolve(hostname);
IPAddress[] address = hostInfo.AddressList;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nIP Address list :");
for(int index=0; index < address.Length; index++)
{
Console.WriteLine(address[index]);
}
}
}

...I always get
Host name : hichetu.a.b

IP Address list
x.x.x.x

Now, How do i get the other ip address y.y.y.y ?

Nov 15 '05 #3
You do it the same way - you just connect to the remote computer. From the
top of my head, try something like:

ManagementClass mgmt = new
ManagementClass(\\\\servername\\root\\cimv2:Win32_ NetworkAdapterConfiguratio
n);
Arild

"HiChetu" <go**********@gawab.com> wrote in message
news:d4**************************@posting.google.c om...
hi Pete Davis,

First of all, thanks for your code. It provided me with more options
to get around my problem.

But, your code returns the ip addresses of the local machine on which
the code runs. I want to get the ipaddresses of any host present in my
domain.

How do i get the ipaddresses of any hosts in my domain??
-- HiChetu
"Pete Davis" <pd******@hotmail.com> wrote in message

news:<90******************************@news.megane tnews.com>...
I'm not sure that you can do it the way you're trying to do it. I could be wrong.

I actually just wrote code to do this last night, though, using WMI. I'm not sure if this is the "best" way, but it seems to work. You can also do it
through unmanaged code, but I prefer to stick with managed code wherever
possible.

A few notes about the code below. The NetworkAdapter class simply stores the IP address list, description, and MAC Address properties. You can save
whatever information you'd like. Search the MSDN for
Win32_NetworkAdapterConfiguration to see the available data. My code only returns adapters that have IP addresses assigned to them.

My code is as follows:

public NetworkAdapterVector GetAdapterList()
{
ManagementClass mgmt = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mgmt.GetInstances();
NetworkAdapterVector adapters = new NetworkAdapterVector();

// Search for adapters with IP addresses
foreach(ManagementObject mob in moc)
{

string[] addresses = (string[])mob.Properties["IPAddress"].Value;
if (null == addresses)
{
continue;
}

NetworkAdapter na = new NetworkAdapter();
na.Description = (string) mob.Properties["Description"].Value;
na.MacAddress = (string) mob.Properties["MACAddress"].Value;
na.IPAddresses = addresses;
adapters.Add(na);
}
return adapters;
}

--
http://www.petedavis.net
"HiChetu" <go**********@gawab.com> wrote in message
news:d4**************************@posting.google.c om...
I have a host which has two NIC cards; one configured for LAN
connections, and another for external connections.

Say the ip address are
1) x.x.x.x - for LAN
2) y.y.y.y - for external

hostname = 'hichetu'

With the following code snippet...

public void TestDNS(string hostname)
{
try
{
IPHostEntry hostInfo = Dns.Resolve(hostname);
IPAddress[] address = hostInfo.AddressList;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nIP Address list :");
for(int index=0; index < address.Length; index++)
{
Console.WriteLine(address[index]);
}
}
}

...I always get
Host name : hichetu.a.b

IP Address list
x.x.x.x

Now, How do i get the other ip address y.y.y.y ?

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lukas Schnieper | last post by:
Hi How can i get the hostname of my Linux PC? I tried os.system('hostname') but i cant save the hostname in a variable like hostname = os.system('hostname') thanks Lukas Schnieper
2
by: James M. | last post by:
I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup with NLB (single Affinity, also using SQLServer session state) that are hosting a few .NET ASP web applications under the Default Website...
11
by: Paul Fi | last post by:
How can i determine IP Address of my machine at runtime without providing any information like HostName? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in...
0
by: James M via .NET 247 | last post by:
(I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup withNLB (single Affinity, also using SQLServer session state) thatare hosting a few .NET ASP web applications under the DefaultWebsite in...
4
by: Chris Morse | last post by:
Does anyone know how to determine the DNS servers for a client machine? I'd like this to work on any .NET enabled platform, which basically means everything except Windows 95. Researching this...
6
by: Eric Rechter | last post by:
Hi, I only want to display the provider name from a hostname, so I need to divide the string to take only de characters from after the before last dot. For example: ...
2
by: slinkp | last post by:
Can anybody explain this one? pw@kermit ~ $ python Python 2.4.3 (#1, Jul 27 2006, 13:07:44) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most...
3
by: Mark Delaney | last post by:
When using the MS SQL 2005 JDBC driver, I now need to have the DNS name resolution to the client correctly set up. If not I get the following error: SQLState: 08S01 SQLError: 0 Message:...
1
by: weird0 | last post by:
Is there a way for particular (not the authorized person who is running the network) to get access to of all the IP address, hostname,MAC IDS and other user information of all the clients on a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.