System.Net.Dns.GetHostAdresses
Hi, my name is Claudionir I`m from Brazil and new in Programming with VS 2005 Express Editipon. So I`m tring to meke a simple project to get the Internet IP (Ex. 201.26.0.172), I tried System.Net.Dns.GetHostAdress, but I wasn`t able to get. My project has a texbox and a button, I just want to get the IP when i clik on the button. Can you help me?
claudionirqs@hotmail.com
Answers
Here is a small console application example using Dns.GetHostAddresses... you might want to tweak it to your requirements..
using System;
using System.Net;
using System.Net.Sockets;
public class DnsListings
{
public static void Main(String[] args)
{
Console.WriteLine(Socket.SupportsIPv6);
String hostname = "";
try
{
hostname = Dns.GetHostName();
if (args.Length == 1)
hostname = args[0];
Console.WriteLine("Getting Dns host entries for hostname " + hostname);
IPAddress[] hosts = Dns.GetHostAddresses(hostname);
foreach (IPAddress address in hosts)
{
Console.WriteLine("Address :{0}", address.ToString());
}}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}}
}
All Replies
Here is a small console application example using Dns.GetHostAddresses... you might want to tweak it to your requirements..
using System;
using System.Net;
using System.Net.Sockets;
public class DnsListings
{
public static void Main(String[] args)
{
Console.WriteLine(Socket.SupportsIPv6);
String hostname = "";
try
{
hostname = Dns.GetHostName();
if (args.Length == 1)
hostname = args[0];
Console.WriteLine("Getting Dns host entries for hostname " + hostname);
IPAddress[] hosts = Dns.GetHostAddresses(hostname);
foreach (IPAddress address in hosts)
{
Console.WriteLine("Address :{0}", address.ToString());
}}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}}
}
I'm using .NET 2.0. I need to discover the link-local IPv6 address of the local machine programmatically, via managed code.
The only IPv6 address that Dns.GetHostAddresses returns is the loopback address, not the link-local one. Note that I can see the IPv6 link local address when I run ipconfig.
Is there a way retrieve this address using managed code?
Thanks!
- Thank for your reply, but I'm creating a Win Form app. It this app I have a Form (Form1), a Label (Label1) and a button (Button1). I would like to show in Label1 the Public IP when I click on button, do you know how can I do that?
Thanx.
menitech


