Skip to content

Instantly share code, notes, and snippets.

@RobertoPrevato
Last active March 11, 2022 15:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertoPrevato/0af45aa686b256eb3cf11525a477d8f5 to your computer and use it in GitHub Desktop.
Save RobertoPrevato/0af45aa686b256eb3cf11525a477d8f5 to your computer and use it in GitHub Desktop.
Useful scripts
"""
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()
# to empty a text file:
truncate -s 0 filename
# To hide files creating an .hidden file;
# for example .pyc files
ls *.py[co] >> .hidden
# operating system info:
cat /etc/*-release
# hardware info:
lscpu
uname -a
# 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