finding out client IP address using vb.net

finding out client IP address using vb.n

Page 1 of 1

9 Replies - 101942 Views - Last Post: 17 July 2008 - 03:26 AM Rate Topic: -----

#1 sumitj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 07-April 05

finding out client IP address using vb.net

Post icon  Posted 07 April 2005 - 07:17 AM

hi,
i'm new to vb.net so if can anyone tell me how can i find out the IP address of the client who is trying to connect to the server. i'm thinking of authenticating the user based on the ip address, since the ip address is going to be static.
thanks,
sumit
Is This A Good Question/Topic? 0
  • +

Replies To: finding out client IP address using vb.net

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: finding out client IP address using vb.net

Posted 07 April 2005 - 08:34 AM

Is this web based or an application...there are different ways to do it based on the type of app it is....NET provides several classes to handle this type of thing.
Was This Post Helpful? 0
  • +
  • -

#3 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: finding out client IP address using vb.net

Posted 12 April 2005 - 07:40 PM

Well, you specified in an email that you needed to do this from a web application using vb.net, so you'll want to do something like the following...
using System.Web.HttpRequest

Dim client_ip as string 

client_ip = Request.UserHostAddress()


There is also a .UserHostName() Method for the request object.
Was This Post Helpful? 0
  • +
  • -

#4 sumitj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 07-April 05

Re: finding out client IP address using vb.net

Post icon  Posted 12 April 2005 - 10:25 PM

Amadeus, on Apr 12 2005, 07:40 PM, said:

Well, you specified in an email that you needed to do this from a web application using vb.net, so you'll want to do something like the following...
using System.Web.HttpRequest

Dim client_ip as string 

client_ip = Request.UserHostAddress()


There is also a .UserHostName() Method for the request object.

Hi, thanx for the quick reply...i'll get back to you if some problem comes...i'll try to break up the IP address n compare it with a range for its validity...if you have some good suggestion do mail me...because after getting the clients IP address i need to validate it with a range of IP address to allow him access to the website...

Thanx,
Sumit
Was This Post Helpful? 1

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: finding out client IP address using vb.net

Posted 13 April 2005 - 06:14 AM

Well, the best way to do that would be to split the string into an array, using the .Split() method with the '.' as the char delimiter. Then you'll have an array of 4 integers (although you'll have to convert from string to integer for each of the four). You can use one or all of those integers to compare to your decided ranges.
Was This Post Helpful? 0
  • +
  • -

#6 sumitj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 07-April 05

Re: finding out client IP address using vb.net

Post icon  Posted 13 April 2005 - 06:18 AM

Amadeus, on Apr 13 2005, 06:14 AM, said:

Well, the best way to do that would be to split the string into an array, using the .Split() method with the '.' as the char delimiter. Then you'll have an array of 4 integers (although you'll have to convert from string to integer for each of the four). You can use one or all of those integers to compare to your decided ranges.

thanx a lot...
Was This Post Helpful? 0
  • +
  • -

#7 LemonMan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: finding out client IP address using vb.net

Posted 20 July 2006 - 07:34 AM

Sometimes host names resolve to more than one IP address. In that case, use this code-


Try
			'Declare new collection
			Dim IpCollection As New Collection

			'Retrieve IP address entries
			'To get a www address 
			Dim i As Integer

			Dim ipE As Net.IPHostEntry = System.Net.Dns.GetHostEntry(-HOSTNAME-)
			Dim IpA() As Net.IPAddress = ipE.AddressList

			For i = 0 To IpA.GetUpperBound(0)
				'Add all to list
				IpCollection.Add(IpA(i).ToString)
			Next

			'Select the right address-

			Dim Ipaddress As String

			Ipaddress = IpCollection.GetValue(-Num-)

		Catch ex As Exception
			MsgBox("An error has occured")
		End Try




Replace -HOSTNAME- witht the host name (www.google.com, etc)

Replace -Num- with the number of the address. 0 returns the first address, 1 returns the second address, and so on...
Was This Post Helpful? 0
  • +
  • -

#8 bhavna.ce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-September 06

Re: finding out client IP address using vb.net

Posted 09 September 2006 - 08:52 PM

But any one can tell that how can i find more then one client ip in the (LAN)network and thier requests using VB.net.
PLZ
PLZ
Was This Post Helpful? 0
  • +
  • -

#9 JENENCHAWLA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-March 07

Re: finding out client IP address using vb.net

Posted 19 March 2007 - 06:18 AM

View PostAmadeus, on 7 Apr, 2005 - 08:34 AM, said:

Is this web based or an application...there are different ways to do it based on the type of app it is....NET provides several classes to handle this type of thing.


I need code for VB6 platform.. W'd Pl. help me out and I need only application.hostaddress or ipaddress..
Was This Post Helpful? 0
  • +
  • -

#10 gever  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 19-June 08

Re: finding out client IP address using vb.net

Posted 17 July 2008 - 03:26 AM

you have to add Imports System.Net

Dim hostname As IPHostEntry = Dns.GetHostByName(hostname)
Dim ip As IPAddress() = hostname.AddressList
msgbox ip(0).ToString()

http://vb.net-inform..._ip_address.htm
Was This Post Helpful? 1

Page 1 of 1