?
Solved

Getting the IP address

Posted on 2006-06-28
9
Medium Priority
?
286 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 600 total points
ID: 17001504
Request.UserHostAddress
0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 17001507
Request.ServerVariables.GetValues("REMOTE_ADDR").GetValue(0)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 25

Accepted Solution

by:
DBAduck - Ben Miller earned 1000 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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