How to get IP address of the browser

本文介绍了一种通过客户端JavaScript和ActiveX控件获取浏览器背后的IP地址和MAC地址的方法。该方法适用于运行Windows操作系统的计算机,并需要在浏览器中启用ActiveX。文章提供了具体的ASP文件示例,展示了如何使用Windows Management Instrumentation (WMI)来获取这些信息。
http://www.faqts.com/knowledge_base/view.phtml/aid/9005

How to get IP address of the browser when its operating behind a proxy/firewall? (applets...activex....??)
i have copied the code in my front page but it doesnt work. i dont have .asp setup.
Can u plz send me a simple javascript for .html page to do this job? just MAC address is required
Nov 23rd, 2006 22:39
Anzer M, Michael Scalise, Silvio Pedroso, Hari prasad, Qamar Ahmad, Built in ActiveX Problem in Windows XP

Hi,
there are some problems with below ActiveX it wont work in two builds of
Windows XP. Details are

The components used
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6"
id="locator" VIEWASTEXT></object>

<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"
id="theId"></object>

It works for all system except two. The specifications of the systems
are as follows:
IE version - 6
OS - Windows Xp Professional version
6.0.2900.2180.xpsp_sp2_rtm.040803-2158
and Windows Xp Professional version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519

The systems are configured exactly like the others. It seems that
something is restricting the Active X control from loading into the page.

Please let me know if there is any work around or patch to this problem...

----End----

Hi,

You may use a client side javascript in order to discover the IP
address.

<script language="javascript">
alert(location.hostaddress);
</script>

(The solution above doesn't work. It retrieves only the public Ip
address, not the IPaddress on the PC behind the firewall/router. My
solution below does work, but it is a bit more complicated. Mike
Scalise 9/18/2003)

This solution does retrieve IP addresses from behind a firewall. It
does have limitations. The client computer must be running Windows. It
requires ActiveX to be enabled in the browser.
The first file uses Windows Management Instrumentation (WMI) to
retrieve the physical address of your network card (MAC Address) and
the IP address currently assigned to that computer. Remember, if client
computer gets an address using DHCP, this Ip address may change daily.
The MAC address never changes. It is burned into your network card and
is supposed to be unique in the world. (In fact, microsoft uses the MAC
address and the curent date and time to generate GUID's. )

The first page does an asyncronous call to the WMI system. When the
async call it is done, then it then automatically posts the data to
another file which displayed the results. Nifty cool.
Mike Scalise



Copy and paste the two ASPFiles below.

The first ASP file- NIC5.ASP

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WMI Scripting HTML</title>

<script FOR="foo" EVENT="OnCompleted(hResult,
pErrorObject, pAsyncContext)" LANGUAGE="JScript">

document.forms[0].txtMACAddr.value=unescape(MACAddr);
document.forms[0].txtIPAddr.value=unescape(IPAddr);
document.forms[0].txtDNSName.value=unescape(sDNSName);
document.formbar.submit();
</script>
<script FOR="foo" EVENT="OnObjectReady(objObject,
objAsyncContext)" LANGUAGE="JScript">

if(objObject.IPEnabled != null && objObject.IPEnabled !
= "undefined" && objObject.IPEnabled == true)
{

if(objObject.MACAddress != null &&
objObject.MACAddress != "undefined")
MACAddr = objObject.MACAddress;


if(objObject.IPEnabled && objObject.IPAddress(0) !=
null && objObject.IPAddress(0) != "undefined")
IPAddr = objObject.IPAddress(0);

if(objObject.DNSHostName != null &&
objObject.DNSHostName != "undefined")
sDNSName = objObject.DNSHostName;

}
</script>

</head>
<body>
<p>


<FONT color="red"><span
ID="info"> </span>. </FONT>
<object classid="CLSID:76A64158-CB41-11D1-8B02-
00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-
00C04FB6C223" id="foo">
</object>

<script LANGUAGE="JScript">

var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync
(foo, 'Win32_NetworkAdapterConfiguration');
</script>
</p>


<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">

<input type="hidden" name="txtMACAddr">
<input type="hidden" name="txtIPAddr">
<input type="hidden" name="txtDNSName">

</form>


</body>
</html>

*************************
This is the second file. It is an ASP page, but you could change it to
plain HTML and use Java to retrieve the form field values, if you
wanted.

NICPost.asp

<HTML>
<HEAD>
</HEAD>
<BODY>
Network Interface Card Information Page
<BR>
<BR>
<BR>
You are at IP Address <STRONG>
<%=request.form("txtIPAddr")%>
</STRONG>
<BR>
Your MAC address on your network card is <STRONG>
<% =request.form("txtMACAddr")%>
</STRONG>
<BR>
Your DNS Host name is <STRONG>
<% =request.form("txtDNSName")%>
</STRONG>
<BR>
<BR>
<BR>
To confirm your IP and MAC address information, go to
the command prompt and
type in
<BR>
<BR>
IPCONFIG/ALL
<BR>
<BR>
ASP reports that your IP Address is <STRONG>
<%
response.Write Request.Servervariables("REMOTE_ADDR")
%>
</STRONG>which is your external WAN IP address that
anyone can see,
<BR>
but maybe be shared by hundreds of users if you use Net
Address Translation
(NAT)
<BR>
through a common router.
</BODY>
</HTML>
我需要找到AvahiSRecordBrowserCallback的具体实现。 #ifndef foolookuphfoo #define foolookuphfoo /*** This file is part of avahi. avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ /** \file avahi-core/lookup.h Functions for browsing/resolving services and other RRs */ /** \example core-browse-services.c Example how to browse for DNS-SD * services using an embedded mDNS stack. */ /** A browsing object for arbitrary RRs */ typedef struct AvahiSRecordBrowser AvahiSRecordBrowser; /** A host name to IP adddress resolver object */ typedef struct AvahiSHostNameResolver AvahiSHostNameResolver; /** An IP address to host name resolver object ("reverse lookup") */ typedef struct AvahiSAddressResolver AvahiSAddressResolver; /** A local domain browsing object. May be used to enumerate domains used on the local LAN */ typedef struct AvahiSDomainBrowser AvahiSDomainBrowser; /** A DNS-SD service type browsing object. May be used to enumerate the service types of all available services on the local LAN */ typedef struct AvahiSServiceTypeBrowser AvahiSServiceTypeBrowser; /** A DNS-SD service browser. Use this to enumerate available services of a certain kind on the local LAN. Use AvahiSServiceResolver to get specific service data like address and port for a service. */ typedef struct AvahiSServiceBrowser AvahiSServiceBrowser; /** A DNS-SD service resolver. Use this to retrieve addres, port and TXT data for a DNS-SD service */ typedef struct AvahiSServiceResolver AvahiSServiceResolver; #include <avahi-common/cdecl.h> #include <avahi-common/defs.h> #include <avahi-core/core.h> AVAHI_C_DECL_BEGIN /** Callback prototype for AvahiSRecordBrowser events */ typedef void (*AvahiSRecordBrowserCallback)( AvahiSRecordBrowser *b, /**< The AvahiSRecordBrowser object that is emitting this callback */ AvahiIfIndex interface, /**< Logical OS network interface number the record was found on */ AvahiProtocol protocol, /**< Protocol number the record was found. */ AvahiBrowserEvent event, /**< Browsing event, either AVAHI_BROWSER_NEW or AVAHI_BROWSER_REMOVE */ AvahiRecord *record, /**< The record that was found */ AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata /**< Arbitrary user data passed to avahi_s_record_browser_new() */ ); /** Create a new browsing object for arbitrary RRs */ AvahiSRecordBrowser *avahi_s_record_browser_new( AvahiServer *server, /**< The server object to which attach this query */ AvahiIfIndex interface, /**< Logical OS interface number where to look for the records, or AVAHI_IF_UNSPEC to look on interfaces */ AvahiProtocol protocol, /**< Protocol number to use when looking for the record, or AVAHI_PROTO_UNSPEC to look on all protocols */ AvahiKey *key, /**< The search key */ AvahiLookupFlags flags, /**< Lookup flags. Must have set either AVAHI_LOOKUP_FORCE_WIDE_AREA or AVAHI_LOOKUP_FORCE_MULTICAST, since domain based detection is not available here. */ AvahiSRecordBrowserCallback callback, /**< The callback to call on browsing events */ void* userdata /**< Arbitrary use suppliable data which is passed to the callback */); /** Prepare a new browsing object for arbitrary RRs */ AvahiSRecordBrowser *avahi_s_record_browser_prepare( AvahiServer *server, /**< The server object to which attach this query */ AvahiIfIndex interface, /**< Logical OS interface number where to look for the records, or AVAHI_IF_UNSPEC to look on interfaces */ AvahiProtocol protocol, /**< Protocol number to use when looking for the record, or AVAHI_PROTO_UNSPEC to look on all protocols */ AvahiKey *key, /**< The search key */ AvahiLookupFlags flags, /**< Lookup flags. Must have set either AVAHI_LOOKUP_FORCE_WIDE_AREA or AVAHI_LOOKUP_FORCE_MULTICAST, since domain based detection is not available here. */ AvahiSRecordBrowserCallback callback, /**< The callback to call on browsing events */ void* userdata /**< Arbitrary use suppliable data which is passed to the callback */); /** Free an AvahiSRecordBrowser object */ void avahi_s_record_browser_free(AvahiSRecordBrowser *b); /** Start querying on an AvahiSRecordBrowser object */ void avahi_s_record_browser_start_query(AvahiSRecordBrowser *b); /** Callback prototype for AvahiSHostNameResolver events */ typedef void (*AvahiSHostNameResolverCallback)( AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, /**< Resolving event */ const char *host_name, /**< Host name which should be resolved. May differ in case from the query */ const AvahiAddress *a, /**< The address, or NULL if the host name couldn't be resolved. */ AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create an AvahiSHostNameResolver object for resolving a host name to an adddress. See AvahiSRecordBrowser for more info on the paramters. */ AvahiSHostNameResolver *avahi_s_host_name_resolver_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *host_name, /**< The host name to look for */ AvahiProtocol aprotocol, /**< The address family of the desired address or AVAHI_PROTO_UNSPEC if doesn't matter. */ AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSHostNameResolverCallback calback, void* userdata); /** Prepare an AvahiSHostNameResolver object for resolving a host name to an adddress. See AvahiSRecordBrowser for more info on the paramters. */ AvahiSHostNameResolver *avahi_s_host_name_resolver_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *host_name, /**< The host name to look for */ AvahiProtocol aprotocol, /**< The address family of the desired address or AVAHI_PROTO_UNSPEC if doesn't matter. */ AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSHostNameResolverCallback calback, void* userdata); /** Start querying on an AvahiSHostNameResolver object */ void avahi_s_host_name_resolver_start(AvahiSHostNameResolver *r); /** Free a AvahiSHostNameResolver object */ void avahi_s_host_name_resolver_free(AvahiSHostNameResolver *r); /** Callback prototype for AvahiSAddressResolver events */ typedef void (*AvahiSAddressResolverCallback)( AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *a, const char *host_name, /**< A host name for the specified address, if one was found, i.e. event == AVAHI_RESOLVER_FOUND */ AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create an AvahiSAddressResolver object. See AvahiSRecordBrowser for more info on the paramters. */ AvahiSAddressResolver *avahi_s_address_resolver_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *address, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSAddressResolverCallback calback, void* userdata); /** Prepare an AvahiSAddressResolver object. See AvahiSRecordBrowser for more info on the paramters. */ AvahiSAddressResolver *avahi_s_address_resolver_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *address, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSAddressResolverCallback calback, void* userdata); /** Start querying on an AvahiSAddressResolver object */ void avahi_s_address_resolver_start(AvahiSAddressResolver *r); /** Free an AvahiSAddressResolver object */ void avahi_s_address_resolver_free(AvahiSAddressResolver *r); /** Callback prototype for AvahiSDomainBrowser events */ typedef void (*AvahiSDomainBrowserCallback)( AvahiSDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create a new AvahiSDomainBrowser object */ AvahiSDomainBrowser *avahi_s_domain_browser_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiDomainBrowserType type, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSDomainBrowserCallback callback, void* userdata); /** Prepare a new AvahiSDomainBrowser object */ AvahiSDomainBrowser *avahi_s_domain_browser_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiDomainBrowserType type, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSDomainBrowserCallback callback, void* userdata); /** Start querying on an AvahiSDomainBrowser object */ void avahi_s_domain_browser_start(AvahiSDomainBrowser *b); /** Free an AvahiSDomainBrowser object */ void avahi_s_domain_browser_free(AvahiSDomainBrowser *b); /** Callback prototype for AvahiSServiceTypeBrowser events */ typedef void (*AvahiSServiceTypeBrowserCallback)( AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create a new AvahiSServiceTypeBrowser object. */ AvahiSServiceTypeBrowser *avahi_s_service_type_browser_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceTypeBrowserCallback callback, void* userdata); /** Prepare a new AvahiSServiceTypeBrowser object. */ AvahiSServiceTypeBrowser *avahi_s_service_type_browser_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceTypeBrowserCallback callback, void* userdata); /** Start querying on an AvahiSServiceTypeBrowser object */ void avahi_s_service_type_browser_start(AvahiSServiceTypeBrowser *b); /** Free an AvahiSServiceTypeBrowser object */ void avahi_s_service_type_browser_free(AvahiSServiceTypeBrowser *b); /** Callback prototype for AvahiSServiceBrowser events */ typedef void (*AvahiSServiceBrowserCallback)( AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name /**< Service name, e.g. "Lennart's Files" */, const char *type /**< DNS-SD type, e.g. "_http._tcp" */, const char *domain /**< Domain of this service, e.g. "local" */, AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create a new AvahiSServiceBrowser object. */ AvahiSServiceBrowser *avahi_s_service_browser_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *service_type /** DNS-SD service type, e.g. "_http._tcp" */, const char *domain, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceBrowserCallback callback, void* userdata); /** Prepare a new AvahiSServiceBrowser object. */ AvahiSServiceBrowser *avahi_s_service_browser_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *service_type /** DNS-SD service type, e.g. "_http._tcp" */, const char *domain, AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceBrowserCallback callback, void* userdata); /** Start querying on an AvahiSServiceBrowser object */ void avahi_s_service_browser_start(AvahiSServiceBrowser *b); /** Free an AvahiSServiceBrowser object */ void avahi_s_service_browser_free(AvahiSServiceBrowser *b); /** Callback prototype for AvahiSServiceResolver events */ typedef void (*AvahiSServiceResolverCallback)( AvahiSServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, /**< Is AVAHI_RESOLVER_FOUND when the service was resolved successfully, and everytime it changes. Is AVAHI_RESOLVER_TIMOUT when the service failed to resolve or disappeared. */ const char *name, /**< Service name */ const char *type, /**< Service Type */ const char *domain, const char *host_name, /**< Host name of the service */ const AvahiAddress *a, /**< The resolved host name */ uint16_t port, /**< Service name */ AvahiStringList *txt, /**< TXT record data */ AvahiLookupResultFlags flags, /**< Lookup flags */ void* userdata); /** Create a new AvahiSServiceResolver object. The specified callback function will be called with the resolved service data. */ AvahiSServiceResolver *avahi_s_service_resolver_new( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, /**< Address family of the desired service address. Use AVAHI_PROTO_UNSPEC if you don't care */ AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceResolverCallback calback, void* userdata); /** Prepare a new AvahiSServiceResolver object. The specified callback function will be called with the resolved service data. */ AvahiSServiceResolver *avahi_s_service_resolver_prepare( AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, /**< Address family of the desired service address. Use AVAHI_PROTO_UNSPEC if you don't care */ AvahiLookupFlags flags, /**< Lookup flags. */ AvahiSServiceResolverCallback calback, void* userdata); /** Start querying on an AvahiSServiceResolver object */ void avahi_s_service_resolver_start(AvahiSServiceResolver *r); /** Free an AvahiSServiceResolver object */ void avahi_s_service_resolver_free(AvahiSServiceResolver *r); AVAHI_C_DECL_END #endif
最新发布
08-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值