Skip to content

Instantly share code, notes, and snippets.

View albertofwb's full-sized avatar

Albert Wang albertofwb

View GitHub Profile
@albertofwb
albertofwb / run_as_root.py
Last active August 23, 2023 04:42
linux 系统以 root 权限运行系统命令
def singleton(cls):
_instance = {}
def inner():
if cls not in _instance:
_instance[cls] = cls()
return _instance[cls]
return inner()
@albertofwb
albertofwb / dig.py
Created April 22, 2023 10:05
implement dig command with python
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import dns.resolver
def check_dns(domain_name: str, dns_server: str):
# Create a DNS resolver instance and set the nameserver to the DNS server you want to query
resolver = dns.resolver.Resolver(configure=False)
resolver.nameservers = [dns_server]
@albertofwb
albertofwb / mdig.py
Created April 21, 2023 02:54
obtain the domain's IP and corresponding real address using dig and ipinfo.io
#!/usr/bin/env python3
import subprocess
import requests
def get_domain_locations(domain_name: str) -> dict:
# Use dig command to retrieve IP addresses of domain
result = subprocess.run(['dig', '+short', domain_name], stdout=subprocess.PIPE)
ip_addresses = result.stdout.decode('utf-8').strip().split('\n')
ip_addresses = [i for i in ip_addresses if i.count('.') == 3]
@albertofwb
albertofwb / git-ssh-auth-win-setup.md
Created March 23, 2023 06:28 — forked from jherax/git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows

Setup SSH Authentication for Git Bash on Windows

Prepararation

  1. Create a folder at the root of your user home folder (Example: C:/Users/username/) called .ssh.
    You can run something like: mkdir -p ~/.ssh
  2. Create the following files if they do not already exist (paths begin from the root of your user home folder):
@albertofwb
albertofwb / StrstrIngoreSubBlanks.cpp
Last active June 12, 2020 09:59
搜索父字符串中的子串,忽略父串中的空白字符
#include <string.h>
#include <assert.h>
struct MatchOffset {
int start;
int end;
int GetMatchedCount() {
return end - start;
}
};
@albertofwb
albertofwb / listfiles_bfs.cpp
Last active November 14, 2019 09:12
广度优先枚举windows 文件路径
#include <Windows.h>
#include <deque>
#include <string>
void ListFilesBFS(const std::string& root_dir)
{
std::deque<std::string> output;
WIN32_FIND_DATA findfiledata;
HANDLE hFind = INVALID_HANDLE_VALUE;
@albertofwb
albertofwb / create_files.py
Last active June 18, 2019 03:59
create files benchmark between windows and posix system
from os import path
from os import mkdir
from os import getenv
from os import name as os_name
from time import time
total_files_count = 12345
MAX_FILES_SINGLE_DIR = 500
DEBUG_DIR_NAME = "TestCreateFiles"
DIR_PREFIX = "dir_"
@albertofwb
albertofwb / SimpleHTTPServerWithUpload.py
Created October 18, 2018 06:33 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@albertofwb
albertofwb / crack.py
Created October 1, 2018 04:13
python hack attack visual affects
#! /usr/bin/env python
# encoding: utf-8
# Edit time: 2018-06-05 20:32
# This scripts print some hack attack affect
# Just makes ordinary people think about we are hacking an account
import sys
from time import sleep
import random
import string
@albertofwb
albertofwb / AnimatedGif.java
Created July 10, 2018 02:13
swt custom widget support gif animation
// copy from: https://stackoverflow.com/questions/13479833/java-swt-animated-gif
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Canvas;