Finding IP address by VB.NET

Finding IP address by VB.NET

Page 1 of 1

2 Replies - 20010 Views - Last Post: 16 April 2006 - 12:43 AM Rate Topic: -----

#1 Debraj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-May 05

Finding IP address by VB.NET

Posted 13 May 2005 - 06:26 AM

Imports System
Imports System.Net.Dns

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim shostname As String
		shostname = System.Net.Dns.GetHostName
		Console.WriteLine("Your Machine Name = " & shostname)
		'Call Get IPAddress
		Console.WriteLine("Your IP = " & GetIPAddress())
		TextBox1.Text = shostname
		TextBox2.Text = "" & GetIPAddress()

	End Sub

	Shared Function GetIPAddress() As String
		Dim oAddr As System.Net.IPAddress
		Dim sAddr As String
		With System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
			oAddr = New System.Net.IPAddress(.AddressList(0).Address)
			sAddr = oAddr.ToString
		End With
		GetIPAddress = sAddr
	End Function


Enjoy

Is This A Good Question/Topic? 0
  • +

Replies To: Finding IP address by VB.NET

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Finding IP address by VB.NET

Posted 13 May 2005 - 06:34 AM

you should post this in the Code Snippets to the right under Visual Basic
Was This Post Helpful? 0
  • +
  • -

#3 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 93
  • Joined: 07-February 06

Re: Finding IP address by VB.NET

Posted 16 April 2006 - 12:43 AM

I'm having problems getting this to work. It's telling me that "imports" is a syntax error - I'm sure it's something else that's affecting it.

Also, it's saying that "(.AddressList(0).Address)" "

J(1515): 'Public Property Address() As Long' is obsolete: 'IPAddress.Address is address family dependant, use Equals method for comparison.'

Admittedly, I'm just trying to plug this into my code. I don't understand what I need to change to get it to work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1