📅  最后修改于: 2023-12-03 15:13:27.080000             🧑  作者: Mango
APIipify is a simple and lightweight Javascript library for making requests to the IPify API. It allows your web application to easily retrieve the public IP address of the user's machine.
You can download the latest version of APIipify from the Github repository or install it via NPM:
npm install apiipify
To use APIipify, simply include the script on your webpage and call the getIP
method:
<script src="apiipify.min.js"></script>
<script>
APIipify.getIP(function(ip) {
console.log(ip);
});
</script>
The getIP
method takes a callback function that will be called with the user's public IP address. You can also specify a response format by passing an optional parameter:
APIipify.getIP(function(ip) {
console.log(ip);
}, 'jsonp');
APIipify also provides error handling for failed requests. You can handle errors by passing a second callback function:
APIipify.getIP(function(ip) {
console.log(ip);
}, function(error) {
console.log(error);
});
APIipify is a great tool for web developers who need to retrieve the public IP address of their users. With its simple interface and lightweight design, it's easy to use and integrate into any web application.