Skip to content

Instantly share code, notes, and snippets.

@rg443a
rg443a / powershell_Get-DnsClientCache.cmd
Last active May 19, 2019 12:20
powershell Get-DnsClientCache
powershell Get-DnsClientCache ^| Export-Csv dnclientcache-1.txt &node c:\rgr\bsync2.js dnclientcache-1.txt
@rg443a
rg443a / iblocklist-dl.sh
Last active May 12, 2018 13:14
iblocklist download lists
#!/usr/bin/env sh
curl -s https://www.iblocklist.com/lists.php | sed -n "s/.*value='\(http:.*\)'.*/\1/p" | xargs curl -L -s | gunzip | grep -P '\d+\.\d+\.\d+\.\d+'
jq -r "[.value, .name, .timestamp] | @tsv" 2018-04-27-1524816001-fdns_a.json
@rg443a
rg443a / ip4ToInt.js
Created June 20, 2018 22:55
ip4ToInt, intToIp4, intToBin, isIp4InCidr, calculateCidrRange
const ip4ToInt = ip =>
ip.split('.').reduce((int, oct) => (int << 8) + parseInt(oct, 10), 0) >>> 0;
const isIp4InCidr = ip => cidr => {
const [range, bits = 32] = cidr.split('/');
const mask = ~(2 ** (32 - bits) - 1);
return (ip4ToInt(ip) & mask) === (ip4ToInt(range) & mask);
};
const isIp4InCidrs = (ip, cidrs) => cidrs.some(isIp4InCidr(ip));
@rg443a
rg443a / suffix-black-list.js
Created January 10, 2019 05:41
suffix blacklist (tld filter)
var suffix_black_list=[
"xml",
"atom",
"rss",
"mml",
"txt",
"jad",
"wml",
"htc",
"woff",
@rg443a
rg443a / psping.txt
Created December 5, 2019 22:25
psping examples
icmp fast ping (50)
psping -i 0 -n 50 www.google.com
tcp ping
psping -i 0 -n 10 www.google.com:443
tcp server for latency and bandwidth tests
psping -s 10.0.0.1:5000
tcp latency test (8KB)
psping -l 8k -n 1000 10.0.0.1:5000
tcp bandwidth test
psping -b -l 8k -n 30s 10.0.0.1:5000
@rg443a
rg443a / inet_aton_ntoa.js
Last active January 2, 2020 06:37
inet_aton, inet_ntoa, ip2int, int2ip
function inet_aton(a) {
return a.split(".").reduce(function(a, b) {
return (a << 8) + parseInt(b, 10);
}, 0) >>> 0;
}
function inet_ntoa(a) {
return (a >>> 24) + "." + (a >> 16 & 255) + "." + (a >> 8 & 255) + "." + (a & 255);
}
@rg443a
rg443a / ip2location-cc.js
Last active January 9, 2021 11:14
ip2location visitor-blocker download [TSV]
(async function() {
var cl = Array.from(document.getElementsByName("countryCodes[]")[0].options).map(v => v.value);
var a=[];
console.log(cl);
for (var cn of cl) {
r = await fetch("https://www.ip2location.com/free/visitor-blocker", {
"headers": {
"content-type": "application/x-www-form-urlencoded",
},
"referrer": "https://www.ip2location.com/free/visitor-blocker",
@rg443a
rg443a / st1-byday.js
Created March 21, 2021 18:26
st list by day
var s=document.body.innerText.split("\n");
console.log(s.length);
var nn=s.map(v=>{try {var x=JSON.parse(v)}catch(err){console.log(v);}return x||[];}).flat();
document.body.innerHTML="<pre>" +
nn.sort(sdl).map(n=>{try{var h=new URL(n.url||n.hostname).hostname}catch(err){h=n.url}; return [n.id,(''+n.rtt).padStart(3),(0.001+n.dl).toFixed(0).padStart(4,' '),(0.001+n.elapsed).toFixed(1).padStart(4,' '),(n.country||n.cc).padEnd(20," "),n.name.padEnd(20," "),n.ip,h||n.url||n.hostname].join("\t");}).join("\n")
+"</pre>";
console.log(nn.length);
function srtt(a,b){return a.rtt-b.rtt}
function sdl(a,b){return b.dl-a.dl}
@rg443a
rg443a / bash_history_rem_dupl.sh
Created April 23, 2021 11:24
bash history remove duplicates
tac $HISTFILE | awk '!x[$0]++' | tac | sponge $HISTFILE
awk '!x[$0]++' ~/.bash_history
tac ~/.bash_history | awk '!x[$0]++' | tac
# https://medium.com/@dblume/have-only-unique-lines-in-your-bash-history-941e3de68c03