Solved

Getting the IP address

Posted on 2006-06-28
9
284 Views
Last Modified: 2012-05-05
How do I get the IP address of a user?  thanks
0
Comment
Question by:MikeMCSD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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