forked from Srar/MemcacheDos
-
Notifications
You must be signed in to change notification settings - Fork 5
/
PacketUtils.ts
52 lines (43 loc) · 1.34 KB
/
PacketUtils.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
export default {
isBroadCast: function (bufs): boolean {
for (var i = 0; i < 6; i++) {
if (bufs[i] != 0xff) {
return false;
}
}
return true;
},
isARP: function (bufs): boolean {
return bufs[12] == 0x08 && bufs[13] == 0x06
},
isIPv4: function (bufs): boolean {
return bufs[12] === 0x08 && bufs[13] === 0x00;
},
isTCP: function (bufs): boolean {
return bufs[23] === 0x06;
},
isIGMP: function (bufs): boolean {
return bufs[23] === 0x02;
},
inetAddr: function (ip) {
var nip = ip.split(".").map(function (item) {
return parseInt(item);
})
var bufs = Buffer.from(nip);
return bufs.readUInt32LE(0);
},
inetNtoa: function (number) {
var bufs = new Buffer(4);
bufs.writeUInt32BE(number, 0);
return `${bufs[3].toString(10)}.${bufs[2].toString(10)}.${bufs[1].toString(10)}.${bufs[0].toString(10)}`;
},
stringToIpAddress: function (ip): Buffer {
var nip = ip.split(".").map(function (item) {
return parseInt(item);
})
return Buffer.from(nip);
},
ipAddressToString: function (bufs) {
return `${bufs[0].toString(10)}.${bufs[1].toString(10)}.${bufs[2].toString(10)}.${bufs[3].toString(10)}`;
}
}