Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the IP address

Posted on 2006-06-28
9
Medium Priority
?
288 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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