forked from williballenthin/govt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtUrlScan.go
49 lines (42 loc) · 1.06 KB
/
vtUrlScan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// vtUrlScan - Requests VirusTotal to scan a given URL
// vtUrlScan -url=http://www.virustotal.com/
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/williballenthin/govt"
)
var apikey string
var apiurl string
var url string
// init - initializes flag variables.
func init() {
flag.StringVar(&apikey, "apikey", os.Getenv("VT_API_KEY"), "Set environment variable VT_API_KEY to your VT API Key or specify on prompt")
flag.StringVar(&apiurl, "apiurl", "https://www.virustotal.com/vtapi/v2/", "URL of the VirusTotal API to be used.")
flag.StringVar(&url, "url", "", "url of a file to as VT about.")
}
// check - an error checking function
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
flag.Parse()
if url == "" {
fmt.Println("-url=<url> missing!")
os.Exit(1)
}
c, err := govt.New(govt.SetApikey(apikey), govt.SetUrl(apiurl))
check(err)
// get an URL report
r, err := c.ScanUrl(url)
check(err)
fmt.Printf("r: %s\n", r)
j, err := json.MarshalIndent(r, "", " ")
check(err)
fmt.Printf("UrlReport: ")
os.Stdout.Write(j)
}