networking

How to calculate how much network IO a python script is using?

How to calculate how much network IO a python script is using? Question: Let’s consider the following file script.py that makes a dummy request: import requests response = requests.get("https://example.com") I can estimate how much network bandwidth I have used by the size of response. What if the script has become complex and involves the use …

Total answers: 1

Python Socket to connect over Global Public IP Address

Python Socket to connect over Global Public IP Address Question: I have been working on a project to connect computers located in different locations together through Python. Initially, while testing, I used my private IP address (I did not know it was private at the time) to connect computers on the same network as mine. …

Total answers: 1

PROBLEM WHILE USING SCAPY (Permission denied)

PROBLEM WHILE USING SCAPY (Permission denied) Question: I am trying to make a simple network scanner in python3 which can scan whole devices on LAN. That’s when i heard about Scapy. However, whenever i try to run my program, it returns an error “PermissionError: [Errno 13] Permission denied” Here’s my code: import scapy.all as scapy …

Total answers: 4

Why we need a carriage return r before the new line character n?

Why we need a carriage return r before the new line character n? Question: In the following code the HTTP protocol needs two newline character but what is the need of the r there. Why can’t we just add two n and send the request? import socket mysock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) mysock.connect((“data.pr4e.org”,80)) cmd = ‘GET http://data.pr4e.org/romeo.txt …

Total answers: 2

Fetching the IP address using MicroPython

Fetching the IP address using MicroPython Question: Trying to use pybricks-micropython Want to get the localhost name/IP address. Can do in CPython with this code… but doesn’t seem to be an equivalent I can find in MicroPython? hostName = socket.gethostname() hostIPA = socket.gethostbyname(hostName) Searching on the net, but cannot seem to find anything I can …

Total answers: 1

What is the proper way to ACTUALLY SEND mail from (Python) code?

What is the proper way to ACTUALLY SEND mail from (Python) code? Question: Disclaimer: I hesitated on the title, due to the broad nature of this question (see below), other options included: How to send a mail from localhost, using Python code only? How to send email from Python code, without usage of external SMTP …

Total answers: 2

Python – Pip Install – Proxy Error – 'Cannot connect to proxy.', OSError'

Python – Pip Install – Proxy Error – 'Cannot connect to proxy.', OSError' Question: I want to install some modules in a Enterprise VM in order to create some Python Scripts. I’m trying to use PIP with Proxy to do it. I’m using this command lines: C:Usersuser>SET HTTPS_PROXY=https://user:[email protected]:8080 C:Usersuser>SET PROXY=http://user:[email protected]:8080 C:Usersuser>pip install datetime To have …

Total answers: 10

What does this line means? s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

What does this line means? s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) Question: What does this line mean? s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) What does this syntax mean socket.socket() and socket.AF_INET`? Can’t we use just AF_INET and Stream as parameter? import socket # for socket import sys try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print "Socket successfully created" except socket.error as err: print "socket creation …

Total answers: 4

Python sockets/port forwarding

Python sockets/port forwarding Question: I’ve written server and client programs with Python. Server.py import socket sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) host = socket.gethostname() port = 5555 sock.bind((host, port)) sock.listen(1) conn, addr = sock.accept() data = "Hello!" data = bytes(data, ‘utf-8’) conn.send(data) sock.close() Client.py on Linux import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = socket.gethostname() port …

Total answers: 2

Setting up BGP Layer Using Scapy

Setting up BGP Layer Using Scapy Question: I am trying to use Scapy to send packets that have a BGP layer I am currently stuck on a rudimentary part of this problem because I am unable to set up the BGP layer. I followed the instructions to set up the regular IP and TCP Layer. …

Total answers: 2