Skip to content

Instantly share code, notes, and snippets.

s@s:~$ unzip -l test1/test-1.zip
Archive:  test1/test-1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       35  2017-05-12 19:05   aaa.txt
        6  2017-05-12 18:55   bbb.txt
        6  2017-05-12 18:56   ccc.txt
---------                     -------
       47                     3 files
@blacknon
blacknon / get_ip_address_list.md
Last active January 30, 2023 01:39
Get IP address list from cidr perl oneliner
echo 192.168.100.9/28|perl -aF[./] -lne'for($i=0;$i<4;$i++){$x.=sprintf("%08b",$F[$i])}$y=$F[4];$k=substr($x,0,$y);$m=2**(32-$y);for($j=0;$j<$m;$j++){$a=$k.sprintf("%0".(32-$y)."b",$j);for($n=0;$n<4;$n++){$b.=".".sprintf(oct("0b".substr($a,$n*8,8)))};$b=~s/^\.//g;print $b;$b=""}'
# もうちょっと短くして改行したもの
echo 192.168.100.9/28|perl -aF[./] -E'
$x.=sprintf("%08b",$F[$_])for 0..3;
$y=$F[4];$z=32-$y;
$m=2**$z;
@blacknon
blacknon / gist:f19d1e94b5f89f3e1fef520d3ecc7b59
Last active January 30, 2023 01:41
Add time stamp to terminal log of script command
script -fq >(awk '{print strftime("%F %T ") $0}{fflush()}'>> PATH) # Linux
script -Fq >(awk '{print strftime("%F %T ") $0}{fflush()}'>> PATH) # Mac
@blacknon
blacknon / test_term_logger.go
Last active January 30, 2023 01:41
Goでターミナルログを記録するサンプルコード
package main
import (
"fmt"
"os"
"time"
"github.com/blacknon/gexpect"
)
@blacknon
blacknon / file_path_walk.go
Last active February 11, 2023 22:14
goでfile path walkするための検証コード
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
)
@blacknon
blacknon / poc_file_read.py
Last active February 11, 2023 22:30
fileを読んで処理する系の処理の動作検証コード(python)
fname = "./test.list"
with open(fname) as f:
content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
print(content)
if 'a' in content:
print("aaa ok")
@blacknon
blacknon / 吐露非狩古鬱.md
Last active January 30, 2023 01:49
シェル芸で「吐露非狩古鬱」をecho-sdで1文字ずつ出力する
seq 5|xargs -I@ bash -c 'echo 吐露非狩古鬱|sed -r "s/[^古鬱]|古鬱/\necho-sd \$(echo &|sed -ey#吐露非#トロピ# -es#狩#カル# -es#古鬱#フルーツ#)!\n/@"|sed '\''/echo-/!s/^/echo -e \\\\n/g;s/^/<(/g;s/$/)/g'\''|eval paste `paste - - -`|sed '\''s/\t//g;2!s/^/'\''`printf \ %.s {1..@}`'\''/g;s/^ //g'\'''
@blacknon
blacknon / term_ssh.go
Last active February 13, 2023 03:18
Golang ssh client (support Control key)
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/terminal"
@blacknon
blacknon / receive_results_with_buffered_channel.go
Created August 14, 2018 10:09
channelで文字列を送信するサンプル
package main
import (
"log"
"strconv"
"time"
)
func logSender(resc chan string) {
for i := 0; i < 10; i++ {
@blacknon
blacknon / ssh_term_with_log.go
Last active January 30, 2023 01:52
goでsshでシェルに接続して、ターミナルログも記録する検証・サンプルコード
package main
import (
"bytes"
"fmt"
"io"
"os"
"os/signal"
"syscall"