473,241 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

How to get IP-Adess of the client (Windows autentication)

Hallo !

I am using IIS-Windows-Authentication in my intranet
(web.config <authentication mode="Windows" /> <identity
impersonate="true" />

How can I get the users (client) IP-Address ?

I think the username can be read with user.identity.name.

Thanks
aaapaul

Nov 19 '05 #1
7 3173
<lv****@gmx.net> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
I am using IIS-Windows-Authentication in my intranet
(web.config <authentication mode="Windows" /> <identity
impersonate="true" />

How can I get the users (client) IP-Address ?


HttpContext.Current.Request.UserHostAddress

However, as has been mentioned countless times before, this is not 100%
reliable.
Nov 19 '05 #2
Hi Mark !

Your statement gives back 127.0.0.1.

This isnīt the IP of the client.

Any suggestions.

Nov 19 '05 #3
<lv****@gmx.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

1) Create a new WebForm called debug.aspx

2) Drop the code at the end of this post into it, and deploy it on your web
server

3) Browse to it from a client machine

<%@ Page language="c#" %>
<%@ Import Namespace="System" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Debug for ASP.NET</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">

<script>

function toggleTable(pstrTable)
{
if(document.getElementById("tbl" + pstrTable).style.display =="none")
{
document.getElementById("tbl" + pstrTable).style.display="block";
document.getElementById("cmd" + pstrTable).value="Hide";
}
else
{
document.getElementById("tbl" + pstrTable).style.display="none";
document.getElementById("cmd" + pstrTable).value="Show";
}
}

</script>
</head>

<body><form>

<input type=button id=cmdCurrentIISContext value="Show"
onclick=toggleTable("CurrentIISContext"); style=width:32pt>
<b>Current server context running IIS (Environment)</b>
<table id="tblCurrentIISContext" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<!--
<tr>
<td>System.Security.Principal.WindowsIdentity.GetC urrent().Name</td>
<td><%// = System.Security.Principal.WindowsIdentity.GetCurre nt().Name
%></td>
</tr>
-->
<tr>
<td>System.Environment.CurrentDirectory</td>
<td><% = System.Environment.CurrentDirectory.ToString() %></td>
</tr>
<tr>
<td>System.Environment.MachineName</td>
<td><% = System.Environment.MachineName.ToString() %></td>
</tr>
<tr>
<td>System.Environment.OSVersion</td>
<td>
<%
/*
4.00.1381 Windows NT 4.0
4.00.1381 Windows NT 4.0 Service Pack 6a 1999-11-30
5.00.2195 Windows 2000 (Windows NT 5.0)
5.00.2195 Windows 2000 (Windows NT 5.0) Service Pack 4 2003-06-26
5.1.2600 Windows XP (Windows NT 5.1)
5.1.2600.2096 Windows XP (Windows NT 5.1) Service Pack 2 RC1 2004-03-11
5.1.2600.2149 Windows XP (Windows NT 5.1) Service Pack 2 RC2 2004-06-10
5.2.3663 Windows Server 2003 RC1
5.2.3718 Windows Server 2003 RC2
5.2.3790 Windows Server 2003 RTM (Windows NT 5.2) 2003-04
6.0.4051 Windows "Longhorn" Client Preview 1 2003-11-02
6.0.4074 Windows "Longhorn" Client Preview 2 2004-05-04
*/
Response.Write(System.Environment.OSVersion.ToStri ng());
System.OperatingSystem osInfo = System.Environment.OSVersion;

switch(osInfo.Platform) // determine the platform
{
case System.PlatformID.Win32Windows: // Win95, Win98, Win98SE, WinMe
{
switch (osInfo.Version.Minor)
{
case 0:
{
Response.Write(" (Windows 95)");
break;
}
case 10:
{
if(osInfo.Version.Revision.ToString() == "2222A")
{
Response.Write(" (Windows 98 Second Edition)");
}
else
{
Response.Write(" (Windows 98)");
}
break;
}
case 90:
{
Response.Write(" (Windows Me)");
break;
}
}
break;
}
case System.PlatformID.Win32NT: // WinNT Win2k, WinXP, Win2k3
{
switch(osInfo.Version.Major)
{
case 3:
{
Response.Write(" (Windows NT 3.51)");
break;
}
case 4:
{
Response.Write(" (Windows NT 4.0)");
break;
}
case 5:
{
switch(osInfo.Version.Minor)
{
case 0:
{
Response.Write(" (Windows 2000)");
break;
}
case 1:
{
Response.Write(" (Windows XP)");
break;
}
case 2:
{
switch(osInfo.Version.Build)
{
case 3663:
{
Response.Write(" (Windows Server 2003 RC1)");
break;
}
case 3718:
{
Response.Write(" (Windows Server 2003 RC2)");
break;
}
case 3790:
{
Response.Write(" (Windows Server 2003)");
break;
}
}
break;
}
}
break;
}
case 6:
{
switch(osInfo.Version.Build)
{
case 4051:
{
Response.Write(" (Windows \"Longhorn\" Client Preview 1)");
break;
}
case 4074:
{
Response.Write(" (Windows \"Longhorn\" Client Preview 2)");
break;
}
}
break;
}
default :
{
Response.Write(" (Unknown)");
break;
}
}
break;
}
}
%>
</td>
</tr>
<tr>
<td>System.Environment.SystemDirectory</td>
<td><% = System.Environment.SystemDirectory.ToString() %></td>
</tr>
<tr>
<td>System.Environment.UserDomainName</td>
<td><% = System.Environment.UserDomainName.ToString() %></td>
</tr>
<tr>
<td>System.Environment.UserName</td>
<td><% = System.Environment.UserName.ToString() %></td>
</tr>
<tr>
<td>System.Environment.Version</td>
<td>
<%
Response.Write(System.Environment.Version.ToString ());
switch(System.Environment.Version.ToString())
{
case "1.0.3705.000" :
{
Response.Write(" (.NET 1.0)");
break;
}
case "1.0.3705.209" :
{
Response.Write(" (.NET 1.0 SP1)");
break;
}
case "1.0.3705.288" :
{
Response.Write(" (.NET 1.0 SP2)");
break;
}
case "1.0.3705.6018" :
{
Response.Write(" (.NET 1.0 SP3)");
break;
}
case "1.1.4322.573" :
{
Response.Write(" (.NET 1.1)");
break;
}
case "1.1.4322.2032" :
{
Response.Write(" (.NET 1.1 SP1)");
break;
}
}
%>
</td>
</tr>
<tr>
<td>System.Environment.WorkingSet</td>
<td><% = (System.Environment.WorkingSet / (1000 *
1024)).ToString("#,###0") + "Mb (" +
System.Environment.WorkingSet.ToString("#,###0") + ")" %></td>
</tr>
</table>
<hr>
<input type=button id=cmdEnvironment value="Show"
onclick=toggleTable("Environment"); style=width:32pt>
<b>Environment Variables (Environment.GetEnvironmentVariables())</b><br>
<table id="tblEnvironment" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<%foreach (DictionaryEntry de in Environment.GetEnvironmentVariables()) {%>
<tr>
<td>
<%= de.Key %>
</td>
<td>
<%= de.Value %>
</td>
</tr>
<% } %>
</table>
<hr>
<input type=button id=cmdRequest value="Show"
onclick=toggleTable("Request"); style=width:32pt>
<b>Request Object (HttpContext.Current.Request)</b><br>
<table id="tblRequest" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<tr>
<td>
.UserHostAddress
</td>
<td>
<%= Request.UserHostAddress %>
</td>
</tr>
<tr>
<td>
.UserHostName
</td>
<td>
<%= Request.UserHostName %>
</td>
</tr>
</table>
<hr>
<input type=button id=cmdRequestServerVariables value="Show"
onclick=toggleTable("RequestServerVariables"); style=width:32pt>
<b>Server Variables (HttpContext.Current.Request.ServerVariables)</b><br>
<table id="tblRequestServerVariables" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<%foreach (string name in HttpContext.Current.Request.ServerVariables) {%>
<tr>
<td>
<%= name %>
</td>
<td>
<%
if (Request.ServerVariables[name] != "")
{
Response.Write(Request.ServerVariables[name]);
}
else
{
Response.Write("&nbsp;");
}
%>
</td>
</tr>
<% } %>
</table>
<hr>
<input type=button id=cmdApplication value="Show"
onclick=toggleTable("Application"); style=width:32pt>
<b>Application Variables (HttpContext.Current.Application)</b><br>
<table id="tblApplication" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<%foreach (string name in HttpContext.Current.Application) {%>
<tr>
<td>
<%= name %>
</td>
<td>
<%= Application[name] %>
</td>
</tr>
<% } %>
</table>
<hr>
<input type=button id=cmdSession value="Show"
onclick=toggleTable("Session"); style=width:32pt>
<b>Session Variables (HttpContext.Current.Session)</b><br>
<table id="tblSession" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<%foreach (string name in HttpContext.Current.Session) {%>
<tr>
<td>
<%= name %>
</td>
<td>
<%= Session[name] %>
</td>
</tr>
<% } %>
</table>
<hr>
<input type=button id=cmdRequestCookies value="Show"
onclick=toggleTable("RequestCookies"); style=width:32pt>
<b>Cookies (HttpContext.Current.Request.Cookies)</b><br>
<table id="tblRequestCookies" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<%foreach (string name in HttpContext.Current.Request.Cookies) {%>
<tr>
<td>
<%= name %>
</td>
<td>
<%= Request.Cookies[name] %>
</td>
</tr>
<% } %>
</table>
<hr>
<%
/*
'System.Web.HttpBrowserCapabilities' does not contain a definition for
'GetEnumerator'
*/
%>
<input type=button id=cmdRequestBrowser value="Show"
onclick=toggleTable("RequestBrowser"); style=width:32pt>
<b>Browser (HttpContext.Current.Request.Browser)</b><br>
<table id="tblRequestBrowser" border=1 style=display:none>
<tr>
<td><b>Key</b></td>
<td><b>Value</b></td>
</tr>
<tr>
<td>.ActiveXControls</td>
<td><%= HttpContext.Current.Request.Browser.ActiveXControl s %></td>
</tr>
<tr>
<td>.AOL</td>
<td><%= HttpContext.Current.Request.Browser.AOL %></td>
</tr>
<tr>
<td>.BackgroundSounds</td>
<td><%= HttpContext.Current.Request.Browser.BackgroundSoun ds %></td>
</tr>
<tr>
<td>.Beta</td>
<td><%= HttpContext.Current.Request.Browser.Beta %></td>
</tr>
<tr>
<td>.Browser</td>
<td><%= HttpContext.Current.Request.Browser.Browser %></td>
</tr>
<tr>
<td>.CDF</td>
<td><%= HttpContext.Current.Request.Browser.CDF %></td>
</tr>
<tr>
<td>.ClrVersion</td>
<td><%= HttpContext.Current.Request.Browser.ClrVersion %></td>
</tr>
<tr>
<td>.Cookies</td>
<td><%= HttpContext.Current.Request.Browser.Cookies %></td>
</tr>
<tr>
<td>.Crawler</td>
<td><%= HttpContext.Current.Request.Browser.Crawler %></td>
</tr>
<tr>
<td>.EcmaScriptVersion</td>
<td><%= HttpContext.Current.Request.Browser.EcmaScriptVers ion %></td>
</tr>
<tr>
<td>.Frames</td>
<td><%= HttpContext.Current.Request.Browser.Frames %></td>
</tr>
<tr>
<td>.JavaApplets</td>
<td><%= HttpContext.Current.Request.Browser.JavaApplets %></td>
</tr>
<tr>
<td>.JavaScript</td>
<td><%= HttpContext.Current.Request.Browser.JavaScript %></td>
</tr>
<tr>
<td>.MajorVersion</td>
<td><%= HttpContext.Current.Request.Browser.MajorVersion %></td>
</tr>
<tr>
<td>.MinorVersion</td>
<td><%= HttpContext.Current.Request.Browser.MinorVersion %></td>
</tr>
<tr>
<td>.MSDomVersion</td>
<td><%= HttpContext.Current.Request.Browser.MSDomVersion %></td>
</tr>
<tr>
<td>.Platform</td>
<td><%= HttpContext.Current.Request.Browser.Platform %></td>
</tr>
<tr>
<td>.Tables</td>
<td><%= HttpContext.Current.Request.Browser.Tables %></td>
</tr>
<tr>
<td>.Type</td>
<td><%= HttpContext.Current.Request.Browser.Type %></td>
</tr>
<tr>
<td>.VBScript</td>
<td><%= HttpContext.Current.Request.Browser.VBScript %></td>
</tr>
<tr>
<td>.Version</td>
<td><%= HttpContext.Current.Request.Browser.Version %></td>
</tr>
<tr>
<td>.W3CDomVersion</td>
<td><%= HttpContext.Current.Request.Browser.W3CDomVersion %></td>
</tr>
<tr>
<td>.Win16</td>
<td><%= HttpContext.Current.Request.Browser.Win16 %></td>
</tr>
<tr>
<td>.Win32</td>
<td><%= HttpContext.Current.Request.Browser.Win32 %></td>
</tr>
</table>
<hr>
<input type=button id=cmdNavigator value="Show"
onclick=toggleTable("Navigator"); style=width:32pt>
<b>Navigator Properties (javascript:navigator)</b><br>
<table id="tblNavigator" border=1 style=display:none>
<tr>
<td><b>Property</b></td>
<td><b>Value</b></td>
</tr>
<tr>
<td>appCodeName</td>
<td><script>document.write(navigator.appCodeName); </script></td>
</tr>
<tr>
<td>appMinorVersion</td> <!--appMajorVersion doesn't exist, for some
reason!-->
<td><script>document.write(navigator.appMinorVersi on);</script></td>
</tr>
<tr>
<td>appName</td>
<td><script>document.write(navigator.appName);</script></td>
</tr>
<tr>
<td>appVersion</td>
<td><script>document.write(navigator.appVersion) ;</script></td>
</tr>
<tr>
<td>browserLanguage</td>
<td><script>document.write(navigator.browserLangua ge);</script></td>
</tr>
<tr>
<td>constructor</td>
<td><script>document.write(navigator.constructor); </script></td>
</tr>
<tr>
<td>cookieEnabled</td>
<td><script>document.write(navigator.cookieEnabled );</script></td>
</tr>
<tr>
<td>cpuClass</td>
<td><script>document.write(navigator.cpuClass);</script></td>
</tr>
<tr>
<td>javaEnabled()</td>
<td><script>document.write(navigator.javaEnabled() );</script></td>
</tr>
<tr>
<td>language</td>
<td><script>document.write(navigator.language);</script></td>
</tr>
<tr>
<td>onLine</td>
<td><script>document.write(navigator.onLine);</script></td>
</tr>
<tr>
<td>opsProfile</td>
<td><script>document.write(navigator.opsProfile) ;</script></td>
</tr>
<tr>
<td>platform</td>
<td><script>document.write(navigator.platform);</script></td>
</tr>
<tr>
<td>securityPolicy</td>
<td><script>document.write(navigator.securityPolic y);</script></td>
</tr>
<tr>
<td>systemLanguage</td>
<td><script>document.write(navigator.systemLanguag e);</script></td>
</tr>
<tr>
<td>taintEnabled()</td>
<td><script>document.write(navigator.taintEnabled( ));</script></td>
</tr>
<tr>
<td>userAgent</td>
<td><script>document.write(navigator.userAgent); </script></td>
</tr>
<tr>
<td>userLanguage</td>
<td><script>document.write(navigator.userLanguage) ;</script></td>
</tr>
<tr>
<td>userProfile</td>
<td><script>document.write(navigator.userProfile); </script></td>
</tr>
</table>
<hr>
<input type=button id=cmdScreen value="Show" onclick=toggleTable("Screen");
style=width:32pt>
<b>Screen Properties (javascript:screen)</b><br>
<table id="tblScreen" border=1 style=display:none>
<tr>
<td><b>Property</b></td>
<td><b>Value</b></td>
</tr>
<tr>
<td>availHeight</td>
<td><script>document.write(screen.availHeight);</script></td>
</tr>
<tr>
<td>availLeft</td>
<td><script>document.write(screen.availLeft);</script></td>
</tr>
<tr>
<td>availTop</td>
<td><script>document.write(screen.availTop);</script></td>
</tr>
<tr>
<td>availWidth</td>
<td><script>document.write(screen.availWidth);</script></td>
</tr>
<tr>
<td>colorDepth</td>
<td><script>document.write(screen.colorDepth);</script></td>
</tr>
<tr>
<td>height</td>
<td><script>document.write(screen.height);</script></td>
</tr>
<tr>
<td>pixelDepth</td>
<td><script>document.write(screen.pixelDepth);</script></td>
</tr>
<tr>
<td>width</td>
<td><script>document.write(screen.width);</script></td>
</tr>
</table>

</form></body>

</html>
Nov 19 '05 #4
Thanks Mark !

Your script runs well. I can see many variables and value.

But what I need is the Windows-IP of the client. It isnīt shown.

Is this possible at all to get this value?

Nov 19 '05 #5
I need something like this:

Dim hostaddresses() As IPAddress
hostaddresses = Dns.GetHostByName(Dns.GetHostName).AddressList
Dim i As Integer
For i = 0 To hostaddresses.GetLength(0) - 1
Response.Write(hostaddresses(i).ToString & "<br>")
Next

Nov 19 '05 #6
<lv****@gmx.net> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
But what I need is the Windows-IP of the client. It isnīt shown.


You've got pretty much all of the possibilities in that script.

When I run it locally, several of the variables contain my machine's
internal IP address i.e. 192.168.0.4

When I browse to it on my public website, they correctly show my cable
modem's external IP address.

I can only think that there's something on your network which is
interfering...
Nov 19 '05 #7
Thanks.

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: StinkFinger | last post by:
All, There are certain scripts that I have that only I want to run, both from home and sometimes work. If I add something like this (below) to the scripts, will this keep out unauthorized use (if...
21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
9
by: Rob | last post by:
I am trying to write a program with VC++ 6.0 to read a txt file which looks like this: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 ...
1
by: Abby | last post by:
I'm writing a code to send/receive udp packet. I'll receive ip address from user (this is the starting ip), then I'll ask user how many ip he wants to connect to. For examples: Please enter 1st...
0
by: Ricky Chan | last post by:
I am using DNSQuery API to get computer name from IP address. However, by below sample code, I don't know how to specify the DNS Address for the field (ByVal aipServers As Integer). any idea?...
1
by: rlc | last post by:
I am using a toolkit, part of which creates TCP/IP connections using a function 'Connect(<local IP>,<local Port>,<Remote IP>,<Remote Port>)'. This function's signiture looks very similar to the...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
20
by: Terry Olsen | last post by:
I'm writing an app that communicates with computers both inside and outside my router. So I need to determine by the remote host's IP address if I need to send them my LAN IP or my Internet IP. ...
4
by: hhlebanon | last post by:
I want to be able to access my trendnet ip camera from the internet without having a static IP assigned from my ISP Provider. I have a DSL Connection at home, connected to a router (trendnet) and...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.