-
Notifications
You must be signed in to change notification settings - Fork 0
/
spit.ts
76 lines (68 loc) · 1.68 KB
/
spit.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import yargs from 'https://deno.land/x/yargs/deno.ts'
import { parse as yamlParse } from 'https://deno.land/[email protected]/encoding/yaml.ts'
type SpitArgs = {
_: string[]
ips: string[]
test: number
config: string
$0: string
}
type SpitConfig = {
hostname: string
username: string
key: string
}
type ScamalyticsApiRequest = {
status: 'ok' | 'error'
error?: string
mode: 'test' | 'live'
ip: string
score: number
risk: 'low' | 'medium' | 'high' | 'very high'
url: string
credits: ScamalyticsCredits
exec: string
}
type ScamalyticsCredits = {
used: number
remaining: number
}
const args: SpitArgs = yargs()
.scriptName('spit')
.command(
'check <ips...>',
'Check a list of ips for scammers',
(yargs: any) => {
return yargs
.positional('ips', {
describe: 'A list of IPs to check against scamalytics api'
})
.option('test', {
description:
'Perform a test request rather than a real one (data will be invalid)',
alias: 't',
default: 0
})
}
)
.option('config', {
description:
'Configuration for application, will contain your api user and key',
alias: 'c',
default: `${Deno.env.get('HOME')}/.spit.yaml`
})
.strictCommands()
.demandCommand(1)
.parse(Deno.args)
console.info(args)
const config = yamlParse(
await Deno.readTextFile(
await Deno.realPath(args.config)
)
) as SpitConfig
args.ips.forEach(async (ip: string) => {
const url = `https://${config.hostname}/${config.username}/?key=${config.key}&ip=${ip}&test=${args.test}`
const resp = await fetch(url)
const data = await resp.json() as ScamalyticsApiRequest
console.log(data)
})