I know PhP can know your IP from
<?php echo $_SERVER['REMOTE_ADDR']; ?>
If the file containing your JS code is parsed by PHP, you should be able to inject the IP-address into the JS code by PHP.
But you can get IP from back-end with AJAX
You can use an HTTP request to call an existing API which provides the IP. For example there is the XML API at domaintools.com, but there should be much more simpler APIs to access.