Sneaky Fingerprint and IP Tracker with React Sneaky fingerprint and IP tracker with React DEV's Worldwide Show and Tell Challenge Presented by Mux: Pitch Your Projects!
importfpfrom"fingerprintjs2";// We re-write the callback into a Promise style,// so it plays nice with React HooksexportconstgetFingerprint=()=>newPromise(resolve=>{fp.get(components=>{resolve(components);});});
获取 IP 地址元数据
基于 IP 的地理定位是将 IP 地址或 MAC 地址映射到联网计算机或移动设备的实际地理位置。地理定位涉及将 IP 地址映射到国家/地区、区域(城市)、经纬度、互联网服务提供商 (ISP) 和域名等信息。更多信息请点击此处。
importReact,{useEffect,useState}from"react";import{getFingerprint}from"./utils";// The method we wrote aboveimportDataTablefrom"./dataTable";// Custom component to render our datafunctionApp(){const[fingerprint,setFingerprint]=useState(null);const[ipData,setIpData]=useState(null);const[showReport,setShowReport]=useState(true);useEffect(()=>{if (showReport){fetch("https://extreme-ip-lookup.com/json")// Get the IP data.then(res=>res.json()).then(ip=>Promise.all([ip,getFingerprint()]))// Get the fingerprint.then(([ip,fp])=>{setFingerprint(fp);// Update the statesetIpData(ip);setShowReport(false);});}},[showReport]);return (<div>{ipData&&fingerprint?(<div><DataTabletitle="IP Data"data={ipData}/><DataTabletitle="Fingerprint"data={fingerprint}/></div>):(<div><h2>Please wait...</h2></div>)}</div>);}exportdefaultApp;