mirror of
https://github.com/Lissy93/web-check.git
synced 2025-05-01 12:54:28 +02:00
⏲ Resolves concurency issues
This commit is contained in:
parent
ee1a9389e4
commit
9018f6fdd1
@ -9,7 +9,7 @@ import ServerLocationCard from 'components/Results/ServerLocation';
|
|||||||
import ServerInfoCard from 'components/Results/ServerInfo';
|
import ServerInfoCard from 'components/Results/ServerInfo';
|
||||||
import HostNamesCard from 'components/Results/HostNames';
|
import HostNamesCard from 'components/Results/HostNames';
|
||||||
import keys from 'utils/get-keys';
|
import keys from 'utils/get-keys';
|
||||||
import { determineAddressType } from 'utils/address-type-checker';
|
import { determineAddressType, AddressType } from 'utils/address-type-checker';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getLocation, ServerLocation,
|
getLocation, ServerLocation,
|
||||||
@ -45,48 +45,78 @@ interface ResultsType {
|
|||||||
const Results = (): JSX.Element => {
|
const Results = (): JSX.Element => {
|
||||||
const [ results, setResults ] = useState<ResultsType>({});
|
const [ results, setResults ] = useState<ResultsType>({});
|
||||||
const [ locationResults, setLocationResults ] = useState<ServerLocation>();
|
const [ locationResults, setLocationResults ] = useState<ServerLocation>();
|
||||||
|
const [ ipAddress, setIpAddress ] = useState<undefined | string>(undefined);
|
||||||
|
const [ addressType, setAddressType ] = useState<AddressType>('empt');
|
||||||
const { address } = useParams();
|
const { address } = useParams();
|
||||||
if (address) {
|
|
||||||
console.log(decodeURIComponent(address));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`https://ipapi.co/${address}/json/`)
|
setAddressType(determineAddressType(address || ''));
|
||||||
.then(function(response) {
|
if (addressType === 'ipV4') {
|
||||||
response.json().then(jsonData => {
|
setIpAddress(address);
|
||||||
console.log(jsonData);
|
}
|
||||||
setLocationResults(getLocation(jsonData));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
console.log(error)
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/* Get IP address from URL */
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchIpAddress = () => {
|
||||||
|
fetch(`/find-url-ip?address=${address}`)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(response);
|
||||||
|
response.json().then(jsonData => {
|
||||||
|
console.log('Get IP Address', jsonData);
|
||||||
|
setIpAddress(jsonData.ip);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log(error)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (!ipAddress) {
|
||||||
|
fetchIpAddress();
|
||||||
|
}
|
||||||
|
}, [address]);
|
||||||
|
|
||||||
|
/* Get IP address location info */
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchIpLocation = () => {
|
||||||
|
fetch(`https://ipapi.co/${ipAddress}/json/`)
|
||||||
|
.then(function(response) {
|
||||||
|
response.json().then(jsonData => {
|
||||||
|
setLocationResults(getLocation(jsonData));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log(error)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (ipAddress) {
|
||||||
|
fetchIpLocation();
|
||||||
|
}
|
||||||
|
}, [ipAddress]);
|
||||||
|
|
||||||
|
/* Get hostnames and server info from Shodan */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const applyShodanResults = (response: any) => {
|
const applyShodanResults = (response: any) => {
|
||||||
// const serverLocation = getLocation(response);
|
|
||||||
const serverInfo = getServerInfo(response);
|
const serverInfo = getServerInfo(response);
|
||||||
const hostNames = getHostNames(response);
|
const hostNames = getHostNames(response);
|
||||||
setResults({...results, serverInfo, hostNames });
|
setResults({...results, serverInfo, hostNames });
|
||||||
}
|
}
|
||||||
const fetchShodanData = () => {
|
const fetchShodanData = () => {
|
||||||
const apiKey = keys.shodan;
|
const apiKey = keys.shodan;
|
||||||
fetch(`https://api.shodan.io/shodan/host/${address}?key=${apiKey}`)
|
fetch(`https://api.shodan.io/shodan/host/${ipAddress}?key=${apiKey}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.error) applyShodanResults(response)
|
if (!response.error) applyShodanResults(response)
|
||||||
})
|
})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
};
|
};
|
||||||
const addressType = determineAddressType(address || '');
|
|
||||||
if (addressType !== 'ipV4') {
|
|
||||||
// Not an IP address, get IP from URL
|
if (ipAddress) {
|
||||||
} else {
|
|
||||||
fetchShodanData();
|
fetchShodanData();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [ipAddress]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResultsOuter>
|
<ResultsOuter>
|
||||||
|
Loading…
Reference in New Issue
Block a user