@@ -42,48 +42,74 @@ <h1>IP Reputation Checker - Both Services</h1>
4242 < div class ="result " id ="result "> </ div >
4343
4444 < script >
45+ function addLabeledValue ( container , label , value ) {
46+ const p = document . createElement ( "p" ) ;
47+ const strong = document . createElement ( "b" ) ;
48+ strong . textContent = `${ label } : ` ;
49+ p . appendChild ( strong ) ;
50+ p . appendChild ( document . createTextNode ( value ?? "N/A" ) ) ;
51+ container . appendChild ( p ) ;
52+ }
53+
54+ const MAX_IP_LENGTH = 45 ;
55+
4556 async function checkBoth ( ) {
4657 const ip = document . getElementById ( "ipInput" ) . value . trim ( ) ;
4758 const resultDiv = document . getElementById ( "result" ) ;
4859
4960 if ( ! ip ) {
50- resultDiv . innerHTML = "<p> Please enter a valid IP address.</p> " ;
61+ resultDiv . textContent = "Please enter a valid IP address." ;
5162 return ;
5263 }
5364
54- resultDiv . innerHTML = "<p>Checking AbuseIPDB and VirusTotal...</p>" ;
65+ if ( ip . length > MAX_IP_LENGTH ) {
66+ resultDiv . textContent = "IP address is too long." ;
67+ return ;
68+ }
69+
70+ resultDiv . textContent = "Checking AbuseIPDB and VirusTotal..." ;
5571
5672 try {
57- const abuseResponse = await fetch ( `/api/abuseipdb?ip=${ ip } ` ) ;
73+ const abuseResponse = await fetch ( `/api/abuseipdb?ip=${ encodeURIComponent ( ip ) } ` ) ;
5874 const abuseData = await abuseResponse . json ( ) ;
5975
60- const virusResponse = await fetch ( `/api/virustotal?ip=${ ip } ` ) ;
76+ const virusResponse = await fetch ( `/api/virustotal?ip=${ encodeURIComponent ( ip ) } ` ) ;
6177 const virusData = await virusResponse . json ( ) ;
6278
63- resultDiv . innerHTML = `
64- <h3>Results for IP: ${ ip } </h3>
79+ resultDiv . textContent = "" ;
80+
81+ const title = document . createElement ( "h3" ) ;
82+ title . textContent = `Results for IP: ${ ip } ` ;
83+ resultDiv . appendChild ( title ) ;
84+
85+ const abuseHeader = document . createElement ( "h4" ) ;
86+ abuseHeader . textContent = "AbuseIPDB" ;
87+ resultDiv . appendChild ( abuseHeader ) ;
88+
89+ addLabeledValue ( resultDiv , "Abuse Confidence Score" , String ( abuseData . data ?. abuseConfidenceScore ?? "N/A" ) ) ;
90+ addLabeledValue ( resultDiv , "Categories" , abuseData . data ?. category ?. join ( ", " ) ?? "N/A" ) ;
91+ addLabeledValue ( resultDiv , "Country" , abuseData . data ?. countryCode ?? "N/A" ) ;
92+ addLabeledValue ( resultDiv , "ISP" , abuseData . data ?. isp ?? "N/A" ) ;
93+ addLabeledValue ( resultDiv , "Domain" , abuseData . data ?. domain ?? "N/A" ) ;
6594
66- <h4>AbuseIPDB</h4>
67- <p><b>Abuse Confidence Score:</b> ${ abuseData . data ?. abuseConfidenceScore || "N/A" } </p>
68- <p><b>Categories:</b> ${ abuseData . data ?. category ?. join ( ", " ) || "N/A" } </p>
69- <p><b>Country:</b> ${ abuseData . data ?. countryCode || "N/A" } </p>
70- <p><b>ISP:</b> ${ abuseData . data ?. isp || "N/A" } </p>
71- <p><b>Domain:</b> ${ abuseData . data ?. domain || "N/A" } </p>
95+ const virusHeader = document . createElement ( "h4" ) ;
96+ virusHeader . textContent = "VirusTotal" ;
97+ resultDiv . appendChild ( virusHeader ) ;
7298
73- <h4>VirusTotal</h4>
74- <p><b>Reputation:</b> ${ virusData . data ?. attributes ?. reputation || "N/A" } </p>
75- <p><b>Network:</b> ${ virusData . data ?. attributes ?. network || "N/A" } </p>
76- <p><b>Last Analysis Stats:</b> ${
77- virusData . data ?. attributes ?. last_analysis_stats
78- ? JSON . stringify ( virusData . data . attributes . last_analysis_stats )
79- : "N/A"
80- } </p>
81- <p><b>Tags:</b> ${ virusData . data ?. attributes ?. tags ?. join ( ", " ) || "N/A" } </p>
82- <p><b>Whois:</b> ${ virusData . data ?. attributes ?. whois || "N/A" } </p>
83- ` ;
99+ addLabeledValue ( resultDiv , "Reputation" , String ( virusData . data ?. attributes ?. reputation ?? "N/A" ) ) ;
100+ addLabeledValue ( resultDiv , "Network" , virusData . data ?. attributes ?. network ?? "N/A" ) ;
101+ addLabeledValue (
102+ resultDiv ,
103+ "Last Analysis Stats" ,
104+ virusData . data ? .attributes ? .last_analysis_stats
105+ ? JSON . stringify ( virusData . data . attributes . last_analysis_stats )
106+ : "N/A"
107+ ) ;
108+ addLabeledValue ( resultDiv , "Tags" , virusData . data ?. attributes ?. tags ?. join ( ", " ) ?? "N/A" ) ;
109+ addLabeledValue ( resultDiv , "Whois" , virusData . data ?. attributes ?. whois ?? "N/A" ) ;
84110 } catch ( error ) {
85111 console . error ( error ) ;
86- resultDiv . innerHTML = "<p> Error fetching data from both services.</p> " ;
112+ resultDiv . textContent = "Error fetching data from both services." ;
87113 }
88114 }
89115 </ script >
0 commit comments