如何使用angularjs获取系统IP地址

Moh*_*een 4 angularjs

需要从angularjs代码获取系统IP地址.

我在谷歌搜索过.每个人都在向js建议第三方.

所以我不想打电话来获取IP?

有没有办法从angularjs获得IP?

我的实际情况是.

需要在每次休息呼叫中发送系统IP

geo*_*awg 8

如何使用AngularJS获取系统IP地址

使用freegeoip.net上的位置服务

angular.module("myApp",[]).run(function($rootScope, $http) {
  var url = "//freegeoip.net/json/";
  $http.get(url).then(function(response) {
    console.log(response.data.ip);
    $rootScope.ip = response.data.ip;
  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/angular/angular.js"></script>
<div ng-app="myApp">
  IP address = {{ip}}
</div>
Run Code Online (Sandbox Code Playgroud)

更新

此API端点已弃用,将于2018年7月1日停止工作.有关详细信息,请访问:https://github.com/apilayer/freegeoip#readme "