Page 1 of 1

IP address recognition

PostPosted: Fri Feb 02, 2018 4:34 am
by HackinHoodLogicsTm
Hi NAB,

Please is it possible to retrieve the IP address from your network and store it in a text field?
Please, any help will be appreciated.

Thanks a lot

Re: IP address recognition

PostPosted: Sun Feb 04, 2018 11:51 pm
by anton
js - can not receive this information, it is necessary to use server languages ​​for this. Or use a third-party service:

Go to the next path and write:

Project>Events...>start-up

BeginJS
var script=document.createElement('script');
script.src='http://ip-jobs.staff-base.spb.ru/ip.cgi';
document.getElementsByTagName('head')[0].appendChild(script);
EndJS


Then, at the event, press the button, write:

BeginJS
$rootScope.myip = IP;
EndJS

Thus, you put the IP address of the current user of the page of your program into the variable [myip].

Re: IP address recognition

PostPosted: Mon Feb 05, 2018 1:39 am
by farhad2008
not work

Re: IP address recognition

PostPosted: Mon Feb 05, 2018 8:26 am
by anton
farhad2008 wrote:not work

working
https://youtu.be/SbfaZlrVlP8

Re: IP address recognition

PostPosted: Mon Feb 05, 2018 1:06 pm
by farhad2008
yes
working for me
thank you

Re: IP address recognition

PostPosted: Mon Feb 05, 2018 4:20 pm
by HackinHoodLogicsTm
Thank you a lot @anton

This code works perfectly but the only problem I have is that I need the local IP address, not the Public IP Address.
Please, any Idea how?

Re: IP address recognition

PostPosted: Tue Feb 06, 2018 12:17 am
by anton
HackinHoodLogicsTm wrote:Thank you a lot @anton

This code works perfectly but the only problem I have is that I need the local IP address, not the Public IP Address.
Please, any Idea how?


To obtain local IP, you can use the following code:

window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
pc.createDataChannel("");
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(ice){
if(!ice || !ice.candidate || !ice.candidate.candidate) return;
var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
$rootScope.myIP = myIP;
pc.onicecandidate = noop;
};

!!!!!!!!!!!!!!! Does not work in IE and Edge ... As always ... !!!!!!![/quote]

Tutorial:
https://youtu.be/bGylNJt8KWY

Re: IP address recognition

PostPosted: Tue Feb 06, 2018 4:53 am
by HackinHoodLogicsTm
Thank you @anton. You are Genius :D

Re: IP address recognition

PostPosted: Tue Feb 06, 2018 5:19 am
by HackinHoodLogicsTm
Ooops the code works well on the browser but when compiled to the android app.

I get this "fd88:4477:7aa7:a800:e07e;xxxxx" instead of the ip.

Please, any ideas why?

Re: IP address recognition

PostPosted: Tue Feb 06, 2018 7:52 am
by anton
HackinHoodLogicsTm wrote:Ooops the code works well on the browser but when compiled to the android app.

I get this "fd88:4477:7aa7:a800:e07e;xxxxx" instead of the ip.

Please, any ideas why?


Excellent. This is IPv6. It turns out that on the android is used not IPv4 and IPv6.