How to find IP address of machine using VB.Net or C#

by Viper 6. March 2009 06:05

Some time back I wrote an article on similar topic How to get IP address of a machine using C#. That article was written in days of .Net1.1. Since then .Net framework has come a long way. Some APIs were deprecated and a lot of new APIs were added. This post is an update on that old article. While I was working on a silverlight socket programming project, I had to deal with lot of Networking APIs. During that process I ended up writing a new method that returns me list of local IP addresses and presenting that to user to decide on what IP address they want to run socket server. Hope this post provides a quick coding tip on how you can get local IP address of your machine.


Private Function GetIPs() As StringCollection
 Dim localIP = New StringCollection()
 Dim localHostName = Dns.GetHostName()
 Dim hostEntry = Dns.GetHostEntry(localHostName)
 ' Grab all ip addesses.
 For Each ipAddr As IPAddress In hostEntry.AddressList
  localIP.Add(ipAddr.ToString())
 Next
 GetIPs = localIP
End Function

Pardon my VB.Net code. I am not very intimate with this language. You can find C# code at old article location

Give your advice to big bosses and make money

Views: 20450

Tags: , ,

.Net | CSharp | Networking | Socket

Comments

4/5/2009 2:33:44 PM #

Pankaj

You can also use Request.UserHostAddress to get user ip address.

Pankaj India

7/27/2009 8:49:46 AM #

mujeres solteras

Brilliant! Thanks for the tips how to find IP address machines.

mujeres solteras United States

8/13/2009 7:09:36 PM #

Oniss Mens White Ceramic

I like your blog curently we are looking for a part time article writer would you be interested?

Oniss Mens White Ceramic United States

8/25/2009 12:06:38 AM #

San Diego Wedding DJ's

Thanks, I've been wondering how this could be done in Silverlight for a while now.

San Diego Wedding DJ's United States

9/23/2009 10:31:11 PM #

online poker

Good post….thanks for sharing.. very useful for me i will bookmark this for my future needed. thanks for a great source.

online poker United States

9/29/2009 4:31:11 AM #

green tea and weight loss

well this is a good post and I wanted to thank you for this great read!! I definitely enjoying every little bit of it .I have you bookmarked to check out new stuff you post...thanks for good info..

green tea and weight loss Spain

10/1/2009 11:04:39 PM #

free diet plans

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

free diet plans Slovenia

10/3/2009 10:17:30 PM #

best teeth whitening products

Very interesting site..Useful information shared..Iam very happy to read this article..thanks for giving us nice info..Keep up the work..

best teeth whitening products Singapore

10/4/2009 12:39:17 AM #

anti aging products

I am very glad to see such information which I was searching for a long time.This made very glad..This site has given us an useful information..

anti aging products Switzerland

10/6/2009 10:23:10 PM #

laptop computer

How can i know or show any computers IP adress while it is connected by internet.....?

laptop computer United States

10/7/2009 2:13:46 AM #

ACNE TREATMENT

This is good site to watch.Thanks for shareing the posts.
Regards,

ACNE TREATMENT United States

10/7/2009 9:55:30 PM #

 Super Colon Cleanse

Some time back I wrote an article on similar topic How to get IP address of a machine using C#. That article was written in days of .Net1.1. Since then .Net framework has come a long way. Some APIs were deprecated and a lot of new APIs were added. This post is an update on that old article

Super Colon Cleanse United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories