use .NET to get IP of my machine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This should be easy to do, however I can't seem to figure it out. How can I
find the IP of my machine using .NET
thanks,
Ron
 
using System;
using System.Net;

class Test {

public static void Main() {
IPAddress[] a = Dns.GetHostByName(Dns.GetHostName()).AddressList;
for (int i=0; i<a.Length; i++)
Console.WriteLine ("IpAddr[{0}]={1}",i,a); }

}

hope this may help
--
Happy Coding
Muhanad YOUNIS
MCSD.NET / MCT
http://myounis.blogspirit.com

Be the first to know visit http://www.jordev.net
 
VB translation...

Imports System
Imports System.Net

Friend Class Test
Public Shared Sub Main()
Dim a() As IPAddress =
Dns.GetHostByName(Dns.GetHostName()).AddressList
For i As Integer = 0 To a.Length
Console.WriteLine("IP Address [" & i.ToString & "] = " &
a(i).ToString)
Next
End Sub
End Class

Just in case the OP doesn't speak C [and yes.. I'm bored :P]
_______________________________________________
The Grim Reaper

mos2128 said:
using System;
using System.Net;

class Test {

public static void Main() {
IPAddress[] a = Dns.GetHostByName(Dns.GetHostName()).AddressList;
for (int i=0; i<a.Length; i++)
Console.WriteLine ("IpAddr[{0}]={1}",i,a); }

}

hope this may help
--
Happy Coding
Muhanad YOUNIS
MCSD.NET / MCT
http://myounis.blogspirit.com

Be the first to know visit http://www.jordev.net


RonB said:
This should be easy to do, however I can't seem to figure it out. How can
I
find the IP of my machine using .NET
thanks,
Ron
 
Back
Top