Solved

Getting the IP address

Posted on 2006-06-28
9
279 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
Comment Utility
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 17

Assisted Solution

by:lem2802
lem2802 earned 150 total points
Comment Utility
Request.UserHostAddress
0
 
LVL 17

Expert Comment

by:lem2802
Comment Utility
Request.ServerVariables.GetValues("REMOTE_ADDR").GetValue(0)
0
 
LVL 9

Expert Comment

by:zaghaghi
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Author Comment

by:MikeMCSD
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I think the problem is something else on that page.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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 …
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now