Public IP_
Find easily your public IP address.
Your public IP is: Loading...
Loading...
Code snippets
Get IP with VueJS component
export default {
name: 'IndexPage',
data(){
return {
ip: 'Loading...'
}
},
methods: {
async getIp(){
this.ip = await fetch('https://cms.acte.ltd/api/ip/json')
.then((response) => { return response.json() } )
.then((data) => { return data.ip })
}
},
mounted(){
this.getIp()
}
}
Get public IP with React component
const PublicIp = () => {
const [ip, setIp] = useState('Loading...');
const getIp = async () => {
try {
let response = await fetch('https://cms.acte.ltd/api/ip/json');
if(response.ok){
let data = await response.json();
setIp(data.ip);
}
} catch (e) {
setIp('Error');
console.error(e);
}
}
useEffect(() => { getIp(); },[]);
return <>{ip}</>;
}