Skip to content

Instantly share code, notes, and snippets.

View wention's full-sized avatar

WENTION wention

View GitHub Profile
@wention
wention / reset-password.py
Created December 18, 2019 08:09
Reset linux system password
import os
import sys
import base64
import crypt
def hash_passwd(passwd):
# SHA-512
return crypt.crypt(passwd, "$6$" + base64.b64encode(os.urandom(16)))
@wention
wention / update_etchosts.py
Created December 30, 2019 07:57
update /etc/hosts with new hostname
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import logging
# imported from parent directory
import utils
LOG = logging.getLogger(__name__)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
def to_unit_auto(size):
unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
uindex = 0 # unit_index
@wention
wention / dnsmasq.conf
Created December 4, 2020 03:14
PXE service via dnsmasq
# disable dns service
port=0
# proxy mode
dhcp-range=192.168.31.254,proxy
enable-tftp
tftp-root=/tftpboot
dhcp-boot=pxelinux.0
@wention
wention / cpu_usage.c
Created January 22, 2021 06:44
get cpu usage under linux
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
int get_cpu_usage()
{
unsigned int stat1[8], stat2[8];
char buf[256];
set ignorecase
set smartcase
set scrolloff=3 " 3 lines above/below cursor when scrolling
" Emulated Plugins
set surround
" Copy to system clipboard as well
set clipboard+=unnamed
@wention
wention / ssh_run_cmd.py
Created July 16, 2021 02:58
python snippet run command via ssh
import os
import paramiko
class SSHClient(paramiko.SSHClient):
def run_cmd(
self,
command,
bufsize=-1,
timeout=None,
get_pty=False,
@wention
wention / jail.conf
Created September 27, 2021 06:27 — forked from AysadKozanoglu/jail.conf
fail2ban nginx 404 400 403 444 filter /etc/fail2ban/filter.d/nginx-4xx.conf enable
# to enable this filter add to jail.conf following (/etc/fail2ban/jail.conf)
# Thanks to -> TheBarret
[nginx-4xx]
enabled = true
port = http,https
logpath = /var/log/nginx/access.log
maxretry = 3
@wention
wention / Startnet.cmd
Last active June 16, 2024 08:31
iPXE Sanboot windows
Wpeinit
ipconfig /all
netsh interface show interface
net use z: \\10.211.55.19\public
z:
.\setup.exe
@wention
wention / nvidia_gpu_passthrough.xml
Last active February 5, 2022 08:26
KVM GPU passthrough helpers
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>win10</name>
<uuid>a03f5f0b-d4e0-49e9-975c-62970b296719</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://microsoft.com/win/10"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>