Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Communications > Get local IP from LocalEndPoint


Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2004, 08:52 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Wink *Solved* Get local IP from LocalEndPoint


Heya,

In my VB6 app I had: my_ip = Winsock1.LocalIP

Now I need the .Net equivalent to this. I have fixed all my other Winsock API stuff would you believe, but I can't work out this simple problem!! hahaha

I have searched MSDN, and adapted what they had to get the following, but it doesnt work. I think maybe because the socket isnt connected?? But I only want the local IP. There must be an easier way.

Code:
Dim tcpSocket As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp) MsgBox(Net.IPAddress.Parse(CType(tcpSocket.LocalEndPoint, Net.IPEndPoint).Address.ToString()))

Last edited by sgt_pinky; 03-30-2004 at 09:15 PM.
Reply With Quote
  #2  
Old 03-30-2004, 09:14 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

Worry not, I have the solution:

Code:
Dim myIPHE As Net.IPHostEntry = Net.Dns.GetHostByName(Net.Dns.GetHostName.ToString) Dim myIP() As Net.IPAddress = myIPHE.AddressList MY_IP_ADDRESS = myIP(0).ToString

The array myIP gives you all IP addresses associated with that computer. Eg: modem connection, local connection etc. I just index zero, because I only use this for licensing anyway.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBS to install a local printer iang Installation / Documentation 0 03-30-2004 05:14 AM
getting local port of browser & listening to it? Csharp Communications 3 01-21-2003 06:04 AM
listening to local port thats open already? Csharp Communications 1 01-10-2003 06:43 PM
Hekp Importing Excel JonM Word, PowerPoint, Outlook, and Other Office Products 2 05-01-2002 09:45 AM
Local database in sync with online database karthiknataraj Database and Reporting 0 02-07-2002 06:58 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->