@@ -3,20 +3,28 @@ import * as dotenv from "dotenv";
33import chalk from "chalk" ;
44import cliProgress from "cli-progress" ;
55import figlet from "figlet" ;
6- import moment from "moment" ;
6+ import moment from "moment" ;
77
88dotenv . config ( ) ;
99
1010const VIRUSTOTAL_API_KEY = process . env . VIRUSTOTAL_API_KEY ;
1111
1212if ( ! VIRUSTOTAL_API_KEY ) {
13- throw new Error ( chalk . red . bold ( "❌ Missing VirusTotal API Key in .env file!" ) ) ;
13+ throw new Error (
14+ chalk . red . bold ( "❌ Missing VirusTotal API Key in .env file!" )
15+ ) ;
1416}
1517
1618export async function scanUrl ( url : string ) : Promise < void > {
1719 try {
18- console . log ( chalk . blue . bold ( figlet . textSync ( "Malware Sniffer" , { horizontalLayout : "full" } ) ) ) ;
19- console . log ( chalk . blue . bold ( `\n🚀 Starting URL Scan: ${ chalk . underline ( url ) } \n` ) ) ;
20+ console . log (
21+ chalk . blue . bold (
22+ figlet . textSync ( "Malware Sniffer" , { horizontalLayout : "full" } )
23+ )
24+ ) ;
25+ console . log (
26+ chalk . blue . bold ( `\n🚀 Starting URL Scan: ${ chalk . underline ( url ) } \n` )
27+ ) ;
2028
2129 const startTime = moment ( ) ;
2230
@@ -73,7 +81,9 @@ export async function scanUrl(url: string): Promise<void> {
7381 progressBar . stop ( ) ;
7482
7583 const engines = scanResults . results ;
76- const detectedEngines = Object . values ( engines ) . filter ( ( res : any ) => res . category === "malicious" ) . length ;
84+ const detectedEngines = Object . values ( engines ) . filter (
85+ ( res : any ) => res . category === "malicious"
86+ ) . length ;
7787 const totalEngines = Object . keys ( engines ) . length ;
7888 const safeScore = ( ( totalEngines - detectedEngines ) / totalEngines ) * 100 ;
7989
@@ -84,13 +94,26 @@ export async function scanUrl(url: string): Promise<void> {
8494 console . log ( chalk . gray ( `🕒 Scan Duration: ${ duration } seconds` ) ) ;
8595 console . log ( chalk . green . bold ( `🔹 Total Engines Checked: ${ totalEngines } ` ) ) ;
8696 console . log ( chalk . red . bold ( `🔸 Malicious Detections: ${ detectedEngines } ` ) ) ;
87- console . log ( chalk . yellow . bold ( `🟡 Suspicious Engines: ${ Object . values ( engines ) . filter ( ( res : any ) => res . category === "suspicious" ) . length } ` ) ) ;
97+ console . log (
98+ chalk . yellow . bold (
99+ `🟡 Suspicious Engines: ${
100+ Object . values ( engines ) . filter (
101+ ( res : any ) => res . category === "suspicious"
102+ ) . length
103+ } `
104+ )
105+ ) ;
88106 console . log ( chalk . green . bold ( `✅ Safe Score: ${ safeScore . toFixed ( 2 ) } %` ) ) ;
89107
90108 console . log ( "\n📈 " + chalk . bold ( "Detection Chart:" ) ) ;
91- console . log ( chalk . green ( "🟩" . repeat ( Math . round ( safeScore / 10 ) ) ) + chalk . red ( "🟥" . repeat ( Math . round ( ( 100 - safeScore ) / 10 ) ) ) ) ;
109+ console . log (
110+ chalk . green ( "🟩" . repeat ( Math . round ( safeScore / 10 ) ) ) +
111+ chalk . red ( "🟥" . repeat ( Math . round ( ( 100 - safeScore ) / 10 ) ) )
112+ ) ;
92113 console . log ( chalk . green . bold ( `Safe: ${ safeScore . toFixed ( 2 ) } %` ) ) ;
93- console . log ( chalk . red . bold ( `Malicious: ${ ( 100 - safeScore ) . toFixed ( 2 ) } %\n` ) ) ;
114+ console . log (
115+ chalk . red . bold ( `Malicious: ${ ( 100 - safeScore ) . toFixed ( 2 ) } %\n` )
116+ ) ;
94117
95118 console . log ( chalk . bold ( "🔍 Detailed Results:" ) ) ;
96119 Object . entries ( engines ) . forEach ( ( [ engine , data ] : any ) => {
@@ -99,9 +122,9 @@ export async function scanUrl(url: string): Promise<void> {
99122 case "malicious" :
100123 categoryColor = chalk . red . bold ( "🛑 Malicious" ) ;
101124 break ;
102- case "harmless" :
103- categoryColor = chalk . green . bold ( "✅ Harmless" ) ;
104- break ;
125+ case "harmless" :
126+ categoryColor = chalk . green . bold ( "✅ Harmless" ) ;
127+ break ;
105128 case "suspicious" :
106129 categoryColor = chalk . yellow . bold ( "⚠️ Suspicious" ) ;
107130 break ;
@@ -117,11 +140,16 @@ export async function scanUrl(url: string): Promise<void> {
117140 } ) ;
118141
119142 if ( detectedEngines > 0 ) {
120- console . log ( chalk . red . bold ( "\n⚠️ WARNING: This URL is potentially unsafe!" ) ) ;
143+ console . log (
144+ chalk . red . bold ( "\n⚠️ WARNING: This URL is potentially unsafe!" )
145+ ) ;
121146 } else {
122147 console . log ( chalk . green . bold ( "\n✅ This URL appears safe!" ) ) ;
123148 }
124149 } catch ( err : any ) {
125- console . error ( chalk . red . bold ( "❌ Error:" ) , err . response ?. data || err . message ) ;
150+ console . error (
151+ chalk . red . bold ( "❌ Error:" ) ,
152+ err . response ?. data || err . message
153+ ) ;
126154 }
127- }
155+ }
0 commit comments