移动端web中js如何js获取局域网ip地址手机ip地址

移动端的H5页面提供了定位的功能,那么如何实现一个最简单的需求-----获取用户当前城市?
你可能搜一下就会找到N篇博客介绍,但是你会发现你看完大段代码之后还是没搞清楚,为了便于大家理解,我精简了代码,只保留了必要的部分。
1、在html页面引入百度地图API(文档地址:)
&script src="http://api.map.baidu.com/api?ak=你的AK码&v=2.0&services=false"&&/script&
2、js代码使用h5的geolocation方法获取坐标,然后使用百度api的getlocation方法翻译成你想要得结果
1 navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.
var lon = position.coords.
var point = new BMap.Point(lon, lat);
// 创建坐标点
// 根据坐标得到地址描述
var myGeo = new BMap.Geocoder();
myGeo.getLocation(point, function (result) {
var city = result.addressComponents.
$('body').html(city);
3、打开手机试一下吧
如果不需要精准的定位,还有一种通过IP地址获取当前城市的方法,采用新浪的api接口。
&script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"&&/script&
var city = remote_ip_info['city'];
alert(city)
阅读(...) 评论()node.js获取客户端IP地址 | 程序狗asp.net、js中获取URL和IP地址方法大全
编辑:www.fx114.net
本篇文章主要介绍了"asp.net、js中获取URL和IP地址方法大全",主要涉及到asp.net、js中获取URL和IP地址方法大全方面的内容,对于asp.net、js中获取URL和IP地址方法大全感兴趣的同学可以参考一下。
HttpContext.Current.Request.Url.ToString()
并不可靠。
如果当前URL为
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼¼&E&otilde
正确的方法是:HttpContext.Current.Request.Url.PathAndQuery1、通过ASP.NET获取
如果测试的url地址是http://www.test.com/testweb/default.aspx
结果如下:
Request.ApplicationPath:&&&&&&&&&&&&&&&&
Request.CurrentExecutionFilePath:&&&&&&&
/testweb/default.aspx
Request.FilePath:&&&&&&&&&&&&&&&&&&&&&&&
/testweb/default.aspx
Request.Path:&&&&&&&&&&&&&&&&&&&&&&&&&&&
/testweb/default.aspx
Request.PhysicalApplicationPath:&&&&&&&&
E:/WWW/testwebRequest.PhysicalPath:&&&&&&&&&&&&&&&&&&&
E:/WWW/testweb/default.aspx
Request.RawUrl:&&&&&&&&&&&&&&&&&&&&&&&&&
/testweb/default.aspx
Request.Url.AbsolutePath:&&&&&&&&&&&&&&&
/testweb/default.aspx
Request.Url.AbsoluteUrl:&&&&&&&&&&&&&&&&http://www.test.com/testweb/default.aspx
Request.Url.Host:&&&&&&&&&&&&&&&&&&&&&&&http://www.test.com/
Request.Url.LocalPath:&&&&&&&&&&&&&&&&&&
/testweb/default.aspx
2、通过JS获取
&table width=100% cellpadding=0 cellspacing=0 border=0 &
thisURL = document.URL;
thisHREF = document.location.
thisSLoc = self.location.
thisDLoc = document.
strwrite = &&tr&&td valign=top&thisURL: &/td&&td&[& +
thisURL + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisHREF: &/td&&td&[&
+ thisHREF + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisSLoc: &/td&&td&[&
+ thisSLoc + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisDLoc: &/td&&td&[&
+ thisDLoc + &]&/td&&/tr&&
document.write( strwrite );
thisDLoc = document. &BR&
thisURL = document.URL; &BR&
thisHREF = document.location. &BR&
thisSLoc = self.location.&BR&
thisTLoc = top.location.
thisPLoc = parent.document.
thisTHost = top.location.
thisHost = location.
strwrite = &&tr&&td valign=top&thisTLoc: &/td&&td&[&
+ thisTLoc + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisPLoc: &/td&&td&[&
+ thisPLoc + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisTHost:
&/td&&td&[& + thisTHost + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisHost: &/td&&td&[&
+ thisHost + &]&/td&&/tr&&
document.write( strwrite );
thisTLoc = top.location. &BR&
thisPLoc = parent.document. &BR&
thisTHost = top.location. &BR&
thisHost = location.&BR&
tmpHPage = thisHREF.split( &/& );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( &/& );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = &&tr&&td valign=top&thisHPage: &/td&&td&[&
+ thisHPage + &]&/td&&/tr&&
strwrite += &&tr&&td valign=top&thisUPage:
&/td&&td&[& + thisUPage + &]&/td&&/tr&&
document.write( strwrite );
&/script&&tr&&td&
=================
1、ASP.NET中获取
获取服务器的IP地址:
using System.N
string myIP,myM
System.Net.IPAddress[] addressList =
Dns.GetHostByName(Dns.GetHostName()).AddressL
addressList.Length&1)
myIP = addressList[0].ToString();
addressList[1].ToString();
addressList[0].ToString();
myMac = &没有可用的连接&;
myIP地址就是服务器端的ip地址。
获取客户端的ip地址,可以使用
//获取登录者ip地址
string ip = Request.ServerVariables[&REMOTE_ADDR&].ToString();
2、通过JS获取
&title&&/title&
http-equiv=&Content-Type& content=&text/
charset=gbk&&
&object classid=&CLSID:76A64158-CB41-11D1-8B02-B6& id=&locator&
style=&display:visibility:hidden&&&/object&
classid=&CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223& id=&foo&
style=&display:visibility:hidden&&&/object&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&form name=&myForm&&
&br/&MAC地址:&input type=&text&
name=&macAddress&&
&br/&IP地址:&input type=&text&
name=&ipAddress&&
&br/&主机名:&input type=&text&
name=&hostName&&
&script language=&javascript&&
sMacAddr=&&;
var sIPAddr=&&;
var sDNSName=&&;
var service =
locator.ConnectServer();
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo,
'Win32_NetworkAdapterConfiguration');
&script FOR=&foo& EVENT=&OnObjectReady(objObject,objAsyncContext)&
LANGUAGE=&JScript&&
&&&&&&&& if(objObject.IPEnabled != null &&
objObject.IPEnabled != &undefined& && objObject.IPEnabled ==
&&&&&&&&&&&&&&&&&&&&&&&&&& if(objObject.IPEnabled &&
objObject.IPAddress(0) !=null && objObject.IPAddress(0) !=
&undefined&)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& sIPAddr =
objObject.IPAddress(0);
&&&&&&&&&&&&&&&&&&&&&&&&&& if(objObject.MACAddress !=
null &&objObject.MACAddress != &undefined&)
&&&&&&&&&&&&&&&&&&&&
sMacAddr = objObject.MACA
&&&&&&&&&&&&&&&&&&&&&&&&&&
if(objObject.DNSHostName != null &&objObject.DNSHostName !=
&undefined&)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& sDNSName =
objObject.DNSHostN
&&&&&&&&& }
&script FOR=&foo& EVENT=&OnCompleted(hResult,pErrorObject, pAsyncContext)&
LANGUAGE=&JScript&&
myForm.macAddress.value=sMacA
myForm.ipAddress.value=sIPA
myForm.hostName.value=sDNSN
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:下次自动登录
现在的位置:
& 综合 & 正文
Node.JS如何获取客户端IP地址
因为涉及兼容性问题,可以通过req.header('x-forwarded-for')与req.connection.remoteAddress来获取IP地址,
下面是封装好的一个函数:
function getClientIp(req) {
var forwardedIpsStr = req.header('x-forwarded-for');
if (forwardedIpsStr) {
var forwardedIps = forwardedIpsStr.split(',');
ipAddress = forwardedIps[0];
if (!ipAddress) {
ipAddress = req.connection.remoteA
return ipA
【上篇】【下篇】拒绝访问 | www.th7.cn | 百度云加速
请打开cookies.
此网站 (www.th7.cn) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(b443a7-ua98).
重新安装浏览器,或使用别的浏览器}

我要回帖

更多关于 js获取本地ip地址 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信