Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get system ip address by using angularjs

Tags:

angularjs

Need to get System IP Address from angularjs code.

I have searched in google. Everyone are suggesting third party from js.

So i dont want to make a call to get IP?

Is there any way to get IP from angularjs?

My actual scenario is.

Need to send system ip in every rest call

like image 831
Mohaideen Avatar asked Feb 04 '23 13:02

Mohaideen


1 Answers

How to get system ip address by using AngularJS

Use the location service at 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;
  });
});
<script src="https://unpkg.com/angular/angular.js"></script>
<div ng-app="myApp">
  IP address = {{ip}}
</div>

Update

This API endpoint is deprecated and will stop working on July 1st, 2018. For more information please visit: https://github.com/apilayer/freegeoip#readme"

like image 190
georgeawg Avatar answered Feb 07 '23 02:02

georgeawg