Skip to content

Instantly share code, notes, and snippets.

View hirusha-adi's full-sized avatar
🎯
Focusing

Hirusha Adikari hirusha-adi

🎯
Focusing
View GitHub Profile
@hirusha-adi
hirusha-adi / detect.md
Last active April 28, 2023 09:28 — forked from thaiphuong5/detect.py
Flask browser detection

Check weather the user request is from a mobile phone or a computer and perform actions accordingly with flask and python3

from flask import request, render_template
import re

browser = request.user_agent.browser
version = request.user_agent.version and int(request.user_agent.version.split('.')[0])
platform = request.user_agent.platform
uas = request.user_agent.string
@hirusha-adi
hirusha-adi / ip_regex_python.py
Last active October 24, 2024 05:54
Python IPV4 / IPV6 Regular Expressions (REGEX)
import re
def is_ipaddr(input_str: str) -> bool:
"""
Check if input string is a valid IP address (both IPv4 and IPv6).
Based on:
IPv4: https://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp
IPv6: https://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
Args:
@hirusha-adi
hirusha-adi / ip_check_python.py
Created October 24, 2024 05:57
Python IPV4 / IPV6 Validation
# based on: https://docs.python.org/3/library/ipaddress.html
import ipaddress
def is_ipaddr(input_str: str) -> bool:
"""
Checks if input string is a valid IP address (both IPv4 and IPv6).
Args:
input_str (str): The string to check.
@hirusha-adi
hirusha-adi / ip_check_advanced.py
Last active October 24, 2024 06:25
Python IPV4 / IPV6 Validation (Advanced)
# based on: https://docs.python.org/3/library/ipaddress.html
import ipaddress
import typing
def is_ipcheck(
value: str,
check_type: typing.Literal[
"addr",