Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,885 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,310 people online right now. Registration is fast and FREE... Join Now!




finding out client IP address using vb.net

 
Reply to this topicStart new topic

finding out client IP address using vb.net, finding out client IP address using vb.n

sumitj
7 Apr, 2005 - 06:17 AM
Post #1

New D.I.C Head
*

Joined: 7 Apr, 2005
Posts: 3

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
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Finding Out Client IP Address Using Vb.net
7 Apr, 2005 - 07:34 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
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.
User is online!Profile CardPM
+Quote Post

Amadeus
RE: Finding Out Client IP Address Using Vb.net
12 Apr, 2005 - 06:40 PM
Post #3

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
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...
CODE

using System.Web.HttpRequest

Dim client_ip as string

client_ip = Request.UserHostAddress()

There is also a .UserHostName() Method for the request object.
User is online!Profile CardPM
+Quote Post

sumitj
RE: Finding Out Client IP Address Using Vb.net
12 Apr, 2005 - 09:25 PM
Post #4

New D.I.C Head
*

Joined: 7 Apr, 2005
Posts: 3

QUOTE(Amadeus @ Apr 12 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...
CODE

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
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Finding Out Client IP Address Using Vb.net
13 Apr, 2005 - 05:14 AM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
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.
User is online!Profile CardPM
+Quote Post

sumitj
RE: Finding Out Client IP Address Using Vb.net
13 Apr, 2005 - 05:18 AM
Post #6

New D.I.C Head
*

Joined: 7 Apr, 2005
Posts: 3

QUOTE(Amadeus @ Apr 13 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.

thanx a lot...
User is offlineProfile CardPM
+Quote Post

LemonMan
RE: Finding Out Client IP Address Using Vb.net
20 Jul, 2006 - 06:34 AM
Post #7

D.I.C Head
Group Icon

Joined: 22 Aug, 2005
Posts: 71


Dream Kudos: 155
My Contributions
Sometimes host names resolve to more than one IP address. In that case, use this code-

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...
User is offlineProfile CardPM
+Quote Post

bhavna.ce
RE: Finding Out Client IP Address Using Vb.net
9 Sep, 2006 - 07:52 PM
Post #8

New D.I.C Head
*

Joined: 8 Sep, 2006
Posts: 4


My Contributions
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
User is offlineProfile CardPM
+Quote Post

JENENCHAWLA
RE: Finding Out Client IP Address Using Vb.net
19 Mar, 2007 - 05:18 AM
Post #9

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 2


My Contributions
QUOTE(Amadeus @ 7 Apr, 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.


I need code for VB6 platform.. W'd Pl. help me out and I need only application.hostaddress or ipaddress..


User is offlineProfile CardPM
+Quote Post

gever
RE: Finding Out Client IP Address Using Vb.net
17 Jul, 2008 - 02:26 AM
Post #10

New D.I.C Head
*

Joined: 19 Jun, 2008
Posts: 19



Thanked: 1 times
My Contributions
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-informations.com/communicati..._ip_address.htm




User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month