Solved

Getting the IP address

Posted on 2006-06-28
9
283 Views
Last Modified: 2012-05-05
How do I get the IP address of a user?  thanks
0
Comment
Question by:MikeMCSD
9 Comments
 
LVL 16

Author Comment

by:MikeMCSD
ID: 17001370
which one is better:

        Dim IP As String = Request.UserHostAddress

        'or

        Dim UserHostAddress As String
        Dim instance As HttpRequest
        Dim value As String
        value = instance.UserHostAddress
0
 
LVL 18

Assisted Solution

by:Elvio Lujan
Elvio Lujan earned 150 total points
ID: 17001504
Request.UserHostAddress
0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 17001507
Request.ServerVariables.GetValues("REMOTE_ADDR").GetValue(0)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:zaghaghi
ID: 17002642
you can do this with javascript like this:

<SCRIPT LANGUAGE="JavaScript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';

function ipval() {
document.myform.ipadd.value=ip;
}

window.onload=ipval
// -->
</script>
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 17004054
I tried getting the IP in the code-behind file like this:
...............
"<tr><td bgcolor=#ffffff>" & Request.UserHostAddress & "</td></tr></table>"

but it causes the application to go to the error page ???

and like this:

IPAdd = Request.ServerVariables.GetValues("REMOTE_ADDR").GetValue(0)

"<tr><td bgcolor=#ffffff>" & IPAdd & "</td></tr></table>"

and that too causes an app. error.  Anyone know why it's doing that??

I just want to write the IP address to a text file. Is there an easy way to do this?  thanks

0
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 250 total points
ID: 17005881
If you are in ASP.NET on the server side code you should be able to do this if nothing else works.

        Dim IPAddress As String
        IPAddress = HttpContext.Current.Request.UserHostAddress

This should give you what you want.

Ben.
0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 100 total points
ID: 17008048
http://www.c-sharpcorner.com/1/get_ip.asp

Also in case of .Net

Using .NET Class

System.Web.HttpContext

There are two ways, either by using:

HttpContext.Current.Request.UserHostAddress;

or

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

The Following Line will get the IP Address of the machine instead of Proxy's IP

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 17010338
thanks everyone ..
For some reason, the page I put this code in causes the application to go to the error page:


    Dim IPAddress As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        IPAddress = HttpContext.Current.Request.UserHostAddress
        .........

I do not why it's doing this.
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 17011026
I think the problem is something else on that page.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question