Last active
March 11, 2022 15:19
-
-
Save RobertoPrevato/0af45aa686b256eb3cf11525a477d8f5 to your computer and use it in GitHub Desktop.
Useful scripts
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
""" | |
aiohttp shooting | |
""" | |
import os | |
import asyncio | |
import aiohttp | |
import time | |
url = "https://example/isalive" | |
sema = asyncio.Semaphore(1000) | |
async def fetch_page(session, k): | |
with await sema: | |
try: | |
with aiohttp.Timeout(20): | |
print("[*] Starting {}".format(k)) | |
start = time.perf_counter() | |
async with session.get(url) as response: | |
delta = time.perf_counter() - start | |
print("Status: {}, Latency: {}, Request: {}".format(response.status, delta, k)) | |
return await response.read() | |
except Exception as ex: | |
print(ex) | |
print("[*] Failed to do request {}. {}".format(k, str(ex))) | |
def shooting(): | |
loop = asyncio.get_event_loop() | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17" | |
} | |
with aiohttp.ClientSession(loop=loop, headers=headers) as session: | |
tasks = [fetch_page(session, k) for k in range(1000)] | |
loop.run_until_complete(asyncio.wait(tasks)) | |
loop.close() | |
shooting() |
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
# to empty a text file: | |
truncate -s 0 filename |
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
# example bash script to fix copyright in files (set years properly) | |
find . -type f -exec sed -i 's/Copyright\s2016/Copyright 2017/g' {} + |
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
# To hide files creating an .hidden file; | |
# for example .pyc files | |
ls *.py[co] >> .hidden |
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
# operating system info: | |
cat /etc/*-release | |
# hardware info: | |
lscpu | |
uname -a |
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
# to display the limit of open files: | |
ulimit -a | |
# to edit it, it's different in every distribution: | |
# in arch linux, do (not sure what works): | |
I solved it by editing /etc/security/limits.conf and adding the following to the end of the file, replacing "username" with that you're using to run whatever software it is that needs that many files open concurrently: | |
@username soft nofile 8192 | |
@username hard nofile 8192 | |
# by editing and uncommenting this entry in /etc/systemd/system.conf: | |
DefaultLimitNOFILE=500000 | |
# changing the /etc/security/limits.conf doesn't work, apparently | |
# https://bbs.archlinux.org/viewtopic.php?id=202694 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment