#networks

1 messages Β· Page 22 of 1

ember ledge
#

And, im responsible for finding contributors but I wanna know how the technicall stuff works as im a programmer myself but not that good.

restive blaze
#

Cryptocurrencies are bad first project

#

but TCP is probably best for P2P protocol

ember ledge
#

Im trying to implement a P2P network for Nodes and users who is trying to transact the cryptocurrency to other wallets , they need to communicate with the Nodes

#

@restive blaze Its not my first project, ive done like 4 projects but ye lol

#

This are some of them

storm saffron
#

Right but I've been programming for 8 years and I wouldn't want to do this

#

What's the basis for the blockchain method

junior apex
#

Hey guys. I have a beginner question:
I'm making a script to mass download Google pronunciation mp3's (for educational use). I'm wondering on whether to use aria2 or requests as my download tool.

#

I like aria2 for its blazing fast parallel downloads, but since it's not native to python, I need to do all the file renaming afterwards (categorizing stuff). Thus, lots of extra read/writing to files. 😦 Should I stick with the tried-and-true requests module instead?

slender steeple
#

mass download, you say?

#

use an async http lib like aiohttp

junior apex
#

Oooh aiohttp looks nice. I'll read more into it.

ember ledge
#

Ok this isnt really in relation to python but I feel like it could be a easy or hard question

#

If I had a powerline adapter upstairs and downstairs providing ethernet to my pc through 1 ethernet port and the router is supplying the other adapter downstairs.

#

Could I just plug the ethernet cable coming out of my upstairs adapter into a splitter and have more ports ( with the splitter plugged in with power as well )

gloomy root
#

if you mean a switch sure

ember ledge
#

Cheers

gloomy root
#

thats a switch yes

ember ledge
#

Cheers

#

Yea I know what a switch looks like I was just wondering if you could connect it via powerline adapter

junior apex
#

@slender steeple WOW. Upon further research aiohttp looks amazing. Since I'm downloading vocab words I was building my own key-value table which was another extraneous task.

#

aiohttp already has a guide on how to build my own url's without having to manually store a bunch of extra info.

plush orbit
#

What's a good beginner switch to start with. I use a Cat 5 cable and it gets tiring having to manually disconnect the chords from one device to the other.

storm saffron
#

there are some pretty good cheap netgear ones around

oak spoke
#

Can I listen to incoming requests from a specific protocol ?

abstract kraken
#

@oak spoke yes? no? maybe? what are you trying to do, be specific.

oak spoke
#

I'm trying to listen to the requests that an online game is sending to me

abstract kraken
#

ok, so you need to do packet capture.

#

do you know what port its sending things to you on? and if its TCP or UDP traffic?

oak spoke
#

UDP probably since it's an online game?

#

And no I'm not sure what port is it

#

Or wait

#

I guess it's TCP

#

Since I want to know if I'm getting a game request or not

#

5000 - 5500 UDP

storm saffron
#

Normally you have a separate port for signalling

#

So you listen on like 5501 for game start requests then send back the port

oak spoke
#

How can I listen to it ?

storm saffron
#

TCP?

#

I would use websockets

oak spoke
#

With python ?

#

Also UDP

storm saffron
#

You mean both

oak spoke
#

I meant it's UDP

ember ledge
#

hi

#
import ftplib

FTP_HOST = "ftp://ftpupload.net/prx001.ihweb.ir/htdocs/ClientUpdates"
FTP_USER = "my_username"
FTP_PASS = "my_password"
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
ftp.encoding = "utf-8"
filename = "test 3.exe"
with open(filename, "wb") as file:
    ftp.retrbinary(f"RETR {filename}", file.write)
ftp.quit()```
#

What's the problem

#

trying to download an exe file from my host

#

socket.gaierror: [Errno 11001] getaddrinfo failed

#

I haven't worked with ftp servers

#

can anyone help please

steep crow
#

@ember ledge
FTP_HOST shoulb be just a hostname, no the full URL πŸ™‚

ember ledge
#

@ember ledge
FTP_HOST shoulb be just a hostname, no the full URL πŸ™‚
@steep crow i must use ftp.cwd()?

storm saffron
#

What

slender steeple
#

@dreamy python post your code

timber zodiac
#

hey, does anyone know why

#
import proxyscrape

collector = proxyscrape.create_collector('default', 'http')  # Create a collector for http resources
proxy = collector.get_proxy({'country': 'united states'})  # Retrieve a united states proxy
print(proxy)```
#

returns none

narrow timber
#

Ok so... I've been trying to handle a socket with context managers such as the with statement and contextlib. Neither close the socket. So my ports clogged with the previous sockets I run.

ember ledge
#
i have this Exception error:
[WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied

and this is my server side script


import socket
import threading
import json
import pickle


host, port = "127.0.0.1", 5555
IP = (host, port)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(IP)

server.listen()


players = []


def send_data(players,data):
    for i in players:
        i.send(data)

def recv_data():
    global players
    try:
        data = server.recv(1024)
        print(data.decode())
    except Exception as e:
        print(e)


def main():
    global host, port, IP, server, players

    while True:
        client, address = server.accept()
        players.append(client)
        print(f"NEW CONNECTION {address}")

        while True:
            _thread = threading.Thread(target=recv_data)
            _thread.start()

        #print(players)


main()

storm saffron
#

do you get that at i.send(data)?

low prism
#
msg = socket.recv(1024)
AttributeError: module 'socket' has no attribute 'recv'
storm saffron
#

is that your whole code

#

you need to make a socket

#

i would recommend reading a tutorial

low prism
#

no seagull lol

#

I made the socket

#

that isn't the code

#

I connected to the server

storm saffron
#

can you show the whole code then

low prism
#
import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((socket.gethostname(), 4081))

msg = socket.recv(1024)
print(msg.decode("utf-8"))
#

it seems like recv is no longer in the socket module

#

so I am getting an attribute error

storm saffron
#

it never was, it's a method of a socket object

#

which in this case is server

#

it needs to know which socket you want to receive from

low prism
#

so what's the issue with the attribute error

#

AttributeError: module 'socket' has no attribute 'server'

#

I meant recv*

#

the server is all good

#

AttributeError: module 'socket' has no attribute 'recv'

storm saffron
#

you need to do server.recv

#

at the moment you're trying to receive data not from a socket

#

it'd be like doing import requests and then making a request and then doing requests.body

low prism
#

Oh I see what you are saying now

#

appreciate that

#

works now, much appreciated man

storm saffron
#

does it work

#

ah nice

#

np

opal orbit
#
from bs4 import BeautifulSoup

page = requests.get('https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains')
soup = BeautifulSoup(page.content, 'html.parser')
patt = '<li><a href="/wiki/.'

for tr in soup.find_all('tr'):
    tds = tr.find_all('td')
    for t in tds:
        if patt in t:
            print(F"TD#{tds.index(t)}", t)

``` It prints nothing at all, what am I doing wrong? Im trying to get a list of top level domain extensions from that link and have stuck in the middle way
cold geyser
#

you could use something like: for link in soup.select('tr td a[href^="/wiki/"]'): instead. link['href'] should then give you the href attribute text

#

I assume it's not working because t is not actually a string and patt in t is simply finding nothing

low prism
#

@storm saffron did you check your messages, I sent you sumn

ember ledge
#

hello can someone help me plzzzzzzzzzz

storm saffron
#

!ask

#

oh ffs did they remove this

#

?ask

#

@ember ledge ask the question and people will help if they can

ember ledge
#

someone is helping me for the moment

slender steeple
#

any resources for learning how layers 1+2 work?

paper dagger
#

can Flask be used to load images like without html just direct img only?

#

for example localhost:8000/camera will load the image directly

slender steeple
#

yes

#

just set the right content type

#

send_file should work

#

@paper dagger

paper dagger
#

thanks will check it!

storm saffron
#

yeah it's the same as just serving up a static image file

#

need to set content type so the browser knows what to do with it, then send a valid image file

#

but if you want live updates without having to constantly reload you might want a slightly different solution

#

@slender steeple anything specific?

stark path
#

@low prism you have made a mistake at server.connect((socket.gethostname(), 4081))
because its something like .connect((socket.gethostbyname(socket.gethostname), 4081)) but i am not sure

#

just stack overflow this line and it shoud show you mistake

opal orbit
#

Can anybody explain me, why If i do import urllib I cannot use urllib.request but when I do import urllib.request then I can? I mean this import logics looks bit off, it should be also imported with the entire urllib

gloomy root
#

Because of how their module will be setup

opal orbit
#

Ok, but what does it mean, or how am I supposed to know it?

slender steeple
#

urllib.request is a submodule of urllib and a distinct module from urllib

#

so you have to import it separately from urllib

storm saffron
#

yeah i guess you could know from looking at the folder structure

#

but the guide will tell you

rare leaf
#

I need help, i tried port forwarding port 80 and the router interface shows up

storm saffron
#

what did you port forward it to

#

if you forwarded it to 192.168.1.1 then that's the router's ip address

#

and you should remove that because that makes you very vulnerable

low isle
#

does anyone know how to use WSS with fastapi? i can't find anything that helps me figure out how i need to implement it

gloomy root
#

It's just a ssl websocket

low isle
#

so the client side is where i'll somehow establish that it's an ssl websocket? the docs dont show much other than "here's how to make a regular websocket"

#

it's the same with the starlette docs

gloomy root
#

They're literally the same thing

#

Just one is ssl

#

Like HTTP and https

low isle
#

so there's nothing different i need to do other than using a url with "wss" in it? lol

rare leaf
#

if you forwarded it to 192.168.1.1 then that's the router's ip address
@storm saffron port forwaded it to my computer

storm saffron
#

what ip

rare leaf
#

my computer's

storm saffron
#

which is

rare leaf
#

why would i give u my ip

storm saffron
#

it's a local ip

rare leaf
#

oh true

storm saffron
#

my computer's local ip is 192.168.1.30

rare leaf
#

it says default gateway 14.1

#

so that isnt my public ip

storm saffron
#

ye

#

hmm

#

and then when you visit public ip it's your router page

rare leaf
#

yes

#

that's on the router's interface

#

what do u think

#

@storm saffron

storm saffron
#

hmm

#

i really don't know

#

what about the 8080

#

does that go to your computer

rare leaf
#

yes

#

that brings up my site

ember ledge
opaque walrus
#

hey guys

#

off topic maybe. but what does >netstat -sp tcp do?

#

@storm saffron are you busy

storm saffron
#

so it will

#

run netstat

#

-s will make it display statistics by protocol, and -p tcp chooses the tcp protocol

opaque walrus
#

@storm saffron So my uncle called the toll number on one of those fake phishing sites

#

according to him, all he did was downloaded logmein hamachi and they ran that command or something

#

is there anything else they could do with his IP?

storm saffron
#

yeah they're gonna pretend that that command shows that he has malware

opaque walrus
#

yes exactly!

storm saffron
#

so for example they sometimes look in event viewer

#

where there's tons of errors that are fine

#

the command on its own won't really do anything bad, it might show them what services are open on his computer

#

do you know what the output of that command was

opaque walrus
#

It showed exactly what you said

#

"hacking links found" "trojan found"

#

then displayed active connections

storm saffron
#

can you show the exact output

opaque walrus
#

Scanned with malwarebytes, showed nothing. They even went as far as to lie on the phone with my uncle saying malwarebytes wouldn't detect it, hah. I ran adwcleaner as well as hitman pro as well. Told him to change his passwords

#

yeah for sure

storm saffron
#

are they 'owner-pc'?

#

if so then it's services using sockets to communicate inside the computer

#

which is normal and fine

opaque walrus
#

if you're referring to my uncle's system. most likely yes. I do not think I changed the PC's name

#

Makes sense.

#

Appreciate your insight very much man! Hope you have a great one

storm saffron
#

np

rare leaf
#

If a cookie of a user is not expired, what header should the server respond with?

cold geyser
#

if the server receives a valid cookie, then the server might not respond with any changes to the cookie what-so-ever. unless maybe it has an expiry date, and you want to update that date.

slender steeple
#

?

winged river
#

I have a website running on port 127.0.0.1:8001 and have allowed port-forwarding to my pc.

#

Then I used whatismyip to get my ip and tried <ip>:8001, but cant access the website?

#

(The second step was done on my phone)

#

Do I miss any step (Im new to this stuff)?

covert blaze
#

make sure you are on the same network when hosting locally

#

also, small world eh? :)

winged river
#

Yeah my phone is in the same network

#

but why wouldnt it work outside the network?
Because Im using a static dns provider?

storm saffron
#

You need to host on 0.0.0.0

#

127.0.0.1 is only open on lan

winged river
#

My django website is now running on 0.0.0.0:8001, but I cant access it , even from the machine Im hosting it on

#

I think the auth-handshake failed

#

I mean, 0.0.0.0 is described as "Non routable"- how is that supposed to hlp me

storm saffron
#

auth handshake

#

wot

winged river
#

I meant authentification but its working now

#

How would I make it available outside my local network?

storm saffron
#

port forward then access from public ip

winged river
#

how do I see my public Ip

#

I mean, shall I use my pc's public Ip?

#

Oh, firefox used https instead of http and thats why it threw the SSL-Erro, but if I just use http.://ip it works

#

Thank you

storm saffron
#

noice

velvet rapids
#

is there anything immediately wrong here?

import socket
from time import sleep

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET,  socket.SO_REUSEADDR, 1)
sock.connect(('echo.websocket.org', 80))

sock.send('GET / HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n'.encode('utf-8'))

while True:
    print(sock.recv(100))
    sleep(0.5)
storm saffron
#

don't think so

#

what goes wrong

velvet rapids
#

I don't get a response, I also tried gateway.discord.gg but I get 400 Bad Request when I send the websocket upgrade request

#

Never mind just figured it out somehow just had to specify the host

fiery hearth
#

Is it possible to fire a function on an HTTPS request? As in another piece of code sends a POST request to a python webserver, and on that request it fires the function?

#

Or something similar

buoyant bison
#

hello im creating a web server for my esp8266 board. when i click a button ('launch') on web server, i want to run a function to enable access point mode. code:

try:
import usocket as socket
except:
import socket

from time import sleep
import network

stationMode = network.WLAN(network.STA_IF)
apMode = network.WLAN(network.AP_IF)

if stationMode.isconnected() == False:
stationMode.active(True)
stationMode.connect('ssid','password')
print('connected to ssid ', stationMode.ifconfig())
else:
print('ssid ', stationMode.ifconfig())

def page():
file = open('index.html', 'r')
html = file.read()
file.close()
return html

serverIP = stationMode.ifconfig([0])
port = 4444

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((serverIP, port))

server.listen(5)
while True:
conn, addr = server.accept()
print("got a connection from %s" % addr)
request = conn.recv(1024)
request = str(request)

print(request)
response = page()
conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-type: text/html\n')
conn.send('Connection: close\n\n')
conn.sendall(response)
gloomy root
#

can i ask why you dont just use a standard web framework

#

or existing webserver

buoyant bison
#

wdym by standard web framework?

gloomy root
#

a pre made web framework / webserver

#

rather than trying to make one with raw sockets with alot of security issues

buoyant bison
gloomy root
#

flask would be an example yes

#

if youre using micro python for this then yikesss

buoyant bison
#

-_-

sand nest
#

Anybody know how to create a recvall function in C++ for socket programming? Need to be able to receive as much a data as possible without it being limited due to the buffer size. Server and Client Socket.

shy pebble
#

I would expect it to already be builtin

sand nest
#

It’s not defined in winsock2.h

#

Attempted to make my own but when receiving data it’s messed up

mental jungle
#

hey guys, does anyone know how to use socket ? i'm doing picoCTF and i'd like to make python scripts to automate tasks, i'm on a task in which i have to use netcat to connect to host 2018shell.picoctf.com and port 36356, to get the flag, so the command on shell is simplync 2018shell.picoctf.com 36356 and it returns me this That wasn't so hard was it? picoCTF{NEtcat_iS_a_NEcESSiTy_9454f3e0}however i would like to do the same in python, can anyone tell me how to do so ?
i saw that i have to use socket but i don't know much about this

quartz kettle
#

fastAPI > flask

slender steeple
#

also checkout pwntools

mental jungle
#

i think that if i can write programs, i can also search for such websites by myself @slender steeple, what i would have liked was for someone to explain me how it works, now i made it work

ember ledge
#

hey im trying to learn pythons asyncio streams know any links apart from thier api cause i don't understand a thing there

lucid raft
#

Does anyone know how to build a graph in NetworkX?

#

specifically a knight's graph

#

like in chess

#

it's basically a graph of all legal moves of the knight on an 8x8 chessboard

slender steeple
#

wrong channel

velvet rapids
#

Does anyone know if socket decodes websocket frames? I don't understand why I'm receiving 5 characters then json... are the 5 characters supposed to represent the length? Or are the frames skewed to the left or something? I'm confused pithink

rancid cosmos
#

anyone know how i could findout the ip range of a mifi hotspot?

slender steeple
#

websockets != regular sockets

velvet rapids
#

But socket can be used for websockets... right?

#

And what am I supposed to use then? pithink

ember ledge
#

I use discord.py and load it on a cog along with the bot, but that error stops it

gloomy root
#

@velvet rapids websockets are just implemented on the HTTP protocol for two way coms keeping the connection alive

velvet rapids
#

I know pithink

gloomy root
#

Everything is built on sockets themselves anyway

rancid cosmos
#

can somebody please explain this answer to me?

#

it's regarding using a subnet to grant privilege to some IPs for a MySQL server

#

I'm a bit confused though, because I don't have a lot of experience with networking, but would it be possible to grant access to the 2nd decimal point and beyong, instead of the third

#

for example instead of 192.168.1.*, 192.168.*

rancid cosmos
#

nvm figured it out

ember ledge
#

hi

#

i wanna start networking

#

i dont know nothing about it

#

can you guys help me

storm saffron
#

well websockets are a special protocol

#

oops i was scrolled up

#

'start networking' how

#

@rancid cosmos never used mysql but replace the 1 with a % like the example maybew

rancid cosmos
#

Yeah I got it to work thx

rancid cosmos
#

The thing is that the example was replaced a decimal point further down, so idk what that means in terms of network addresses

#

It did work however

low isle
#

i dont need to, but im just kinda curious

low isle
junior vault
#

Gg mods

cloud pasture
#

TIL you can use IPv6 addresses in connection strings but it requires square brackets

paper dagger
#
<html>
  <body>
      <img src="{{ url_for('video_feed') }}" />
  </body>
</html>
#

i just wanted to see how I can capture it and display it with a CV player in another computer but from the same network

astral quarry
#

i use aiohttp, i created request handler, and i want to extract ip address from request, so how can i do this

gleaming ivy
#

@astral quarry you would use socket library for this...more specifically ```py
import socket
print(socket.gethostbyname('host name'))

storm saffron
#

request.remote in the handler

#

Why switch to socket just for this s

neat nymph
#

is socket and network programming same thing??

elfin dove
#

is it possible to host a single server (like a discord bot or a flask server) on two machines which are in sync with each other and if one of the machine is down then the other machine compensates. Like two machines acting as one. (I am new to networking so not sure if this makes sense)

storm saffron
#

Yes, you would have a third gateway server which directs incoming traffic to one of them

elfin mesa
#

hey guys, trying to test my API using postman, I get the following error: CORS Error: The request has been blocked because of the CORS policy

#

Is this a problem from my (postman/chrome) end -> API, or from API -> me?

#

I'm unsure how to solve it after googling

ember ledge
#

can I ask a question about s3 in aws here?

thorn belfry
#

Is this the right channel to ask about pymodbus?

wicked wren
#

does random headers causes this kinda errors?

('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
#

ping me up if anyone knows?

gloomy root
#

no

#

it means the host just closed the connection

wicked wren
#

but without headers works well πŸ€”

gloomy root
#

no? That purely depends on what the client is doing

wicked wren
#

it works well without headers

#

thats what i meant

gloomy root
#

probably because its changing how the client responds

wicked wren
#

umm...ok

storm saffron
#

what kind of random headers

#

and in what

#

is this http?

ember ledge
#

Hey I'm having an issue with Apache. I have a web server that I'm trying to host 2 websites on. My file structure and settings all seem correct, but one of them gets the response of the other and I can't for the life of me understand why

#
.
β”œβ”€β”€ apache2.conf
β”œβ”€β”€ sites-available
β”‚Β Β  β”œβ”€β”€ default-ssl.conf
β”‚Β Β  β”œβ”€β”€ morganarnold.ca.conf
β”‚Β Β  └── onequotes.ca.conf
└── sites-enabled
    β”œβ”€β”€ morganarnold.ca.conf -> ../sites-available/morganarnold.ca.conf
    └── onequotes.ca.conf -> ../sites-available/onequotes.ca.conf
#

this is part of the file tree for /etc/apache2

#
.
β”œβ”€β”€ morganarnold.ca
β”‚Β Β  └── public_html
β”‚Β Β      └── index.html
└── onequotes.ca
    └── public_html
        └── index.html
#

and this is the file tree for /var/www

#

any help would be hugely appreciated

#
<VirtualHost *:80>
        ServerAdmin ...
        ServerName onequotes.ca
        ServerAlias www.onequotes.ca
        DocumentRoot /var/www/onequotes.ca/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#

this is the contents of onequotes.ca.conf

#
<VirtualHost *:80>
        ServerAdmin ...
        ServerName morganarnold.ca
        ServerAlias www.morganarnold.ca
        DocumentRoot /var/www/morganarnold.ca/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#

and this that of morganarnold.ca.conf

#

pardon all the posting

lavish marten
#

What do you mean by "one of them gets the response of the other"?

ember ledge
#

for some reason

#

and I have tried clearing my cache

lavish marten
#

Try specifying 'DirectoryIndex index.html' in the virtual host file, restart apache and see if that changes anything

ember ledge
#

still no good, unfortunately

ember ledge
#

Okay so I've spent more time trying to figure this out and if i delete morganarnold.ca.conf neither site loads, but it works fine if onequotes.ca.conf is gone

#

I am just WILDLY confused

brazen otter
#

Which is the most useful library to be able to access a website, login, scrape and download some pdf files?

gleaming ivy
#

@brazen otter Well, it depends on use case, usually requests is the way to go, but you can even simulate a browser with selenium (useful for advanced web scraping).

#

For most of the projects, the combination requests + bs4 is pretty good and efficient.

wicked wren
#

hi there guys

#

btw my real question is how to encode headers in hpack while webcrawling with requests?

stark steeple
#

Guys my server-client Program Only connects 2 computers on the same wifi

#

How can I modify it To Work On diffrent Wifis?

#

here are the codes

#

server:

#

import socket
import time

def send(Text):
c.send(bytes(Text , 'utf-8'))

Socket

IP = socket.gethostbyname(socket.gethostname())
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)

s.bind((IP, 1080))
connections = 3
s.listen(connections)

print(f"\nListening at IP: {IP}\n")

try:
c,addr = s.accept()
name = c.recv(1024).decode()
Machinename = "Server"
send(Machinename)

print(f"connected with {name}\nIP = {addr[0]}\n ")

connected = True

except ConnectionRefusedError:
print("connnection lost with " , name)
time.sleep(5)
quit()

while connected:
try:
Message = c.recv(1024).decode()
print(f"\n{name}: " , Message)
if Message == "Disconnect":
send("Disconnecting..")
connected = False
c.close()
print("Client disconnected succseffully")
time.sleep(5)
break
message = input("What do you want to send: ")
send(message)
print("\nYou: " , message)
except ConnectionResetError:
print("The Client was disconnected ( From The client side)")
connected = False
time.sleep(5)
quit()

cold geyser
#

if you want to accept connections from "anywhere", then you need to listen on the special IP "0.0.0.0" on the server side.

stark steeple
#

and Do i need to Modify Anything on the Client side?

#

Here is the client code:

cold geyser
#

usually you don't

stark steeple
#

import socket
import time

def send(txt):
s.send(bytes(txt, "utf-8") )
IP = input("What is the ip: ")
print("\n")
try:
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)

s.connect((IP , 1080))
Connected = True
Name = input("What is your name? ")
send(Name)
MachineName = rec= s.recv(1024).decode()    

except socket.gaierror:
print("No current Servers running")
time.sleep(5)
quit()
except ConnectionRefusedError:
print("The Machine refused connection")
time.sleep(5)
quit()
while Connected:
try:
msg = input("\nWhat do you want to send: ")
send(msg)
print(f"You: {msg}\n")
recmsg = s.recv(1024).decode()
print(f"{MachineName}: {recmsg}\n")
if recmsg == "Disconnecting..":
print("Server disconnected succsessfully")
Connected = False
time.sleep(5)
quit()
except ConnectionResetError:
print("Server Was Disconnected ( From the server side )")
Connected = False
time.sleep(5)
quit()

import socket
import time

def send(txt):
s.send(bytes(txt, "utf-8") )
IP = input("What is the ip: ")
print("\n")
try:
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)

s.connect((IP , 1080))
Connected = True
Name = input("What is your name? ")
send(Name)
MachineName = rec= s.recv(1024).decode()    

while Connected:
try:
msg = input("\nWhat do you want to send: ")
send(msg)
print(f"You: {msg}\n")
recmsg = s.recv(1024).decode()
print(f"{MachineName}: {recmsg}\n")
if recmsg == "Disconnecting..":
print("Server disconnected succsessfully")
Connected = False
time.sleep(5)
quit()
except ConnectionResetError:
print("Server Was Disconnected ( From the server side )")
Connected = False
time.sleep(5)
quit()

#

So I need to replace IP with '0.0.0.0'?

cold geyser
#

on the server side, yes

stark steeple
#

No This Is the Client Code so Instead of taking Input in IP I replace it with '0.0.0.0'?

cold geyser
#

no

#

on the client side you use a normal ip

#

it's only the server side that needs to bind to 0.0.0.0

stark steeple
#

So Is This The correct code:

#
import socket
import time

def send(Text):
    c.send(bytes(Text , 'utf-8')) 


# Socket

IP = socket.gethostbyname(socket.gethostname())
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)

s.bind(('0.0.0.0' ,  1080))
connections = 3
s.listen(connections)

print(f"\nListening at IP: {IP}\n")


try:
    c,addr = s.accept()
    name = c.recv(1024).decode()
    Machinename = "Server"
    send(Machinename)

    print(f"connected with {name}\nIP = {addr[0]}\n ")
    
    connected = True
except ConnectionRefusedError:
    print("connnection lost with " , name)
    time.sleep(5)
    quit()

        
while connected:
    try:
        Message = c.recv(1024).decode()
        print(f"\n{name}: " , Message)
        if Message == "Disconnect":
            send("Disconnecting..")
            connected = False
            c.close()
            print("Client disconnected succseffully")
            time.sleep(5)
            break
        message = input("What do you want to send: ")
        send(message)
        print("\nYou: " , message)
    except ConnectionResetError:
        print("The Client was disconnected ( From The client side)")
        connected = False
        time.sleep(5)
        quit()   
cold geyser
#

well, the print is wrong, but you can probably ignore that

stark steeple
#

And Here is the Client Code:

cold geyser
#

would've been easier to just do: IP = "0.0.0.0"

stark steeple
#
import socket
import time


def send(txt):
    s.send(bytes(txt, "utf-8") )
IP = input("What is the ip: ")
print("\n")
try:
    s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)

    s.connect((IP , 1080))
    Connected = True
    Name = input("What is your name? ")
    send(Name)
    MachineName = rec= s.recv(1024).decode()    
except socket.gaierror:
    print("No current Servers running")
    time.sleep(5)
    quit()
except ConnectionRefusedError:
    print("The Machine refused connection")
    time.sleep(5)
    quit()
while Connected:
    try:
        msg = input("\nWhat do you want to send: ")
        send(msg)
        print(f"You: {msg}\n")
        recmsg = s.recv(1024).decode()
        print(f"{MachineName}: {recmsg}\n")
        if recmsg == "Disconnecting..":
            print("Server disconnected succsessfully")
            Connected = False
            time.sleep(5)
            quit()
    except ConnectionResetError:
        print("Server Was Disconnected ( From the server side )")
        Connected = False
        time.sleep(5)
        quit()

#

Ok

#

Any changes in the client code?

cold geyser
#

no

stark steeple
#

Ok So When Client asks Me To write the Ip of The Server What do i write?

cold geyser
#

the ip that you want to connect to

#

could be localhost a.k. 127.0.0.1, or your LAN IP

#

(usually 192.168.....)

stark steeple
#

I did not understand

cold geyser
#

or a public IP, assuming your router, if you have one, is forwarding the correct ports.

#

what did you not understand?

stark steeple
#

That When Client takes IP input I write The Server Computers IP?

cold geyser
#

yes, usually the ip where the server is running

#

if it's on the same machine, it can be the localhost IP, if it's in the same LAN, it can be the server computers LAN ip

stark steeple
#

Not on the Same Computer

#

So if the Server Computers IP is '129.12.123.204' I write that In the IP input?

cold geyser
#

yes, maybe

stark steeple
#

Let me Try And Get Back

#

Ip is socket.gethostbyname(socket.gethostname()) ?

#

If I write That In IP in client it Gives Timeout error

#

@cold geyser ??

cold geyser
#

that was on the server side, right? you don't need that line any more if you set IP to "0.0.0.0"

stark steeple
#

No On the Client side when I ask : IP = input("What is the Ip of The Server: ")

#

@cold geyser ????

cold geyser
#

yes, and? I was expecting more... usually after "when" comes a "then"

stark steeple
#

Ok Wait

cold geyser
#

if you get a timeout error, it's because it couldn't connect.

#

ip wrong maybe

#

how did you get that 129.12.. ip that you mentioned above?

stark steeple
#

socket.gethostbyname(socket.gethostname())

cold geyser
#

what about that?

stark steeple
#

IP = socket.gethostbyname(socket.gethostname())

#

print('server is running on ' , IP)

cold geyser
#

I already said, that thing is on your server side code and you don't need it because you set the bind IP to "0.0.0.0"

stark steeple
#

But then How will I get an IP to connect On the Client Side?

cold geyser
#

you know it by looking it up

#

in your servers network settings or whatever

stark steeple
#

I am ON windows

cold geyser
#

is the server on windows as well?

stark steeple
#

server and Client Are on Diffrent Windows Machines

cold geyser
#

yes, then on the server, open "cmd.exe" and type: "ipconfig"

stark steeple
#

Then?

cold geyser
stark steeple
#

Yes

#

I am There

#

Now?

cold geyser
#

that 192... is your servers ip address for the lan

#

use that one

stark steeple
#

I am Putting That In the Client.connect('192...' , Port)

#

It doesnt work Over 2 diffrent wifis

cold geyser
#

completely different wifis?

stark steeple
#

Yes

gleaming ivy
cold geyser
#

what's your networks structure? what routers are involved?

stark steeple
#

What???

#

English Please

#

Where to find network structuer... routers involved....

gleaming ivy
#

What the heck is the problem here? 🀣

cold geyser
#

@gleaming ivy mitmproxy is a tool than can do that for you. It's quite a sophisticated toolkit

#

and it's written in python

gleaming ivy
#

i want to build my own proxy library using sockets

#

i already did some

stark steeple
#

Shut up @gleaming ivy

gleaming ivy
#

but they are so crappy

gloomy root
#

that is going to be much harder than your probably think also can yall chill

stark steeple
#

Sani Just Tell me What to do Next?

cold geyser
#

sorry, but honestly I think you have to read up on how networks work in general.

stark steeple
#

Ok Bye

gloomy root
stark steeple
#

is there any other way than socket Proggramming To send Data Over diffrent networks in python???

gloomy root
#

that depends on the data but everything in networking uses sockets

cold geyser
#

asyncio is a higher level library. But you still have to figure out the correct IPs to connect with

gloomy root
#

i really wouldnt say asyncio is higher level

#

in alot of places its alot more complex and still requires you using sockets

gleaming ivy
#

@cold geyser actually the problem is not building the TCP proxy, but to make the game client connect route the traffic through the proxy, and since the game has official servers and not a prompt of the address (like Minecraft)....yes, really easy...

#

i don't even know how to re a game

gloomy root
#

theres a diffrent between writing a simple proxy and writing a proper proxy

gleaming ivy
#

i thought about putting in a different AP on a rasp

gloomy root
#

Production grade Proxies are very complicated and have alot of things they need to do to maintain security and performance

gleaming ivy
#

it's just an amateur proxy for a game, not a proxy that you would advertise online

#

❀️ RevEng py_guido

#

i thought about putting in a different AP on a rasp
is there a simpler way?

#

let's say the game runs only on Windows, but the proxy could also work for Linux...

cold geyser
#

I think I did something like that using mitmproxy. I had to configure my network settings to route the traffic from my windows machine, where the game was running, to another machine (linux in that case), where mitmproxy was set up.

#

additionally I had to add a fake root cert on my windows machine, so I could sniff out the encrypted data as well

gleaming ivy
#

what's the command, even for powershell, for routing traffic for one source ip?

#

iproute or something?

#

as i remember, it is also possible by modifing the hosts file

cold geyser
#

I have no idea. that was years ago, when I did that

#

mitmproxy docs probably have something about that

storm saffron
#

@cold geyser don't think modern games tend to accept windows root certs

#

generally pinned i believe

ember ledge
#

Are there any other places I could try asking an Apache question? I tried here, but it didn't fix my problem

velvet rapids
#

can someone give an example use case for socket.sockpair?

gilded pebble
#

Hello guys
I've done something really stupid. https://www.geeksforgeeks.org/kali-linux-aircrack-ng/
And my wifi icon in the system tray is gone!
when I type wifi in my terminal. it shows zero. But the internet is working fine.
I tried looking for a sol in arch wiki and all that. I am unable to fix this!

ember ledge
#

is there a way to use python to change my proxy ever 10 minutes from a lit?
so like it picks a proxy from a list like proxys = [11.13.3443, 112.232.3222, 222.23.44.5]

slender steeple
#

@ember ledge requests?

#

or system wide

dense atlas
#

!rule 5

errant bayBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious or inappropriate. Do not help with ongoing exams. Do not provide or request solutions for graded assignments, although general guidance is okay.

dense atlas
#

[sorry, but using proxies, especially in this way, seems like something that probably crosses the line]

ember ledge
#

how dose this break a law

#

@dense atlas

dense atlas
#

it's not that it's directly illegal, [though often the kinds of lists of proxies you'd be working from are compromised or unintentionally open systems] it's more that the kinds of things you'd do with it are probably not okay at best in a very dark gray area

crimson perch
#

I have a (python, console) script that interacts with an API (over a library), when attempting to authenticate it wants to me solve a captcha, yet no real way of actually doing that (as its all in the console), how should i go about fixing that?

#

(its never asked me to solve a captcha before, I'm not sure if the library author did something, or the API, or something, but it's something I have to somehow overcome)

#

I have a Response object, and the text property gives me HTML code, which leads to the page where the captcha should be

storm saffron
#

is the api an official api

#

what's the library

crimson perch
#

there's no documentation for the API

#

and authentication is a different sub-page of the main one, which i noticed isn't API friendly

storm saffron
#

what's the library though

crimson perch
#

pixivapi

#

just that

copper hearth
#

Im looking for some modules that will help me capture video streams or just single frames πŸ˜›

storm saffron
#

from what

copper hearth
#

directly from web page, for example https://www.earthcamtv.com/

storm saffron
#

well inspect elemnet shows this is a video stream

#

also rule whatever it is may come into play soon

elder spoke
#

hey, i'm having some trouble turning my socket local server into one that can be accessed by anyone, would anyone here be willing to help me with that?

storm saffron
#
  1. host on 0.0.0.0 not localhost or 127.0.0.1
  2. port forward on your router
  3. access from external ip
#

have you done those

#

if so what's not working

elder spoke
#

i havent tried 2 or 3, ill see about that. thanks πŸ™‚

#

i'm new to networking and I don't know much

copper hearth
#

also rule whatever it is may come into play soon
@storm saffron I should request bytes from that src link? hmm I could try something like that

grave fractal
warped relic
#
import asyncio
import websockets

async def server(websocket, path): 
    while True:
        val = input("Enter your message: ")
        await websocket.send(val)



start_server = websockets.serve(server, "localhost", 5000)


asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
#

my messages aren't sending to the client

#

it works when it's not in the while loop

grave fractal
#

do you get an error?

warped relic
#

no

grave fractal
#

well i literally know nothing but try putting in a sleep in the while loop

#

just to see if that changes stuff O:

warped relic
#

it didn't work

grave fractal
#

and if its not in a while loop it works but only once?

warped relic
#

yeah

grave fractal
#

what you might wanna do, is have a while loop, that then sends the val to a function and in there put the await, gimme a sec

#
import asyncio
import websockets

def sendMsg(val):
  await websocket.send(val)

async def server(websocket, path): 
    while True:
        val = input("Enter your message: ")
        sendMsg(val)

start_server = websockets.serve(server, "localhost", 5000)

asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()```
warped relic
#

now it's erroring "coroutine 'sendMsg' was never awaited"

grave fractal
#

i think await makes it so the python script waits for when it has time to send stuff, but since there is a while loop it kinda never has time?? idk i need to google what await does

#

what you might be able to do is that, after you send a message, you just send the user back to the function where you input the message, so thats kinda a loop, idk :>

gloomy root
#

await... awaits the coroutine

#

if you dont know what coroutines and futures are you should probably learn about asyncio and async in python before starting this

warped relic
#

@gloomy root how would you write this?

gloomy root
#

if you dont know what coroutines and futures are you should probably learn about asyncio and async in python before starting this
@gloomy root

grave fractal
#

"When you call await, the function you're in gets suspended while whatever you asked to wait on happens, and then when it's finished, the event loop will wake the function up again and resume it from the await call, passing any result out."

#

isnt that just a function that calls a function with a return O::

#

but ig that when you use async nothing is synced and this is kinda a way to sunc it again? (kinda)

#

@gloomy root did i get it?

gloomy root
#

not really

grave fractal
#

awh

#

can you gimme a project that requires asyncio? so i can kinda get into it?

hollow saddle
#

coroutines remembers me of kotlin and threads

gloomy root
#

Discord.py, Sanic, aiohttp, Websockets, FastAPI, Starlette, Pyre, etc....

grave fractal
#

discord bot, got it ;>

upbeat forge
#

hey, i'm pretty familiar with sockets and was exploring ssl for secure transmission. a lot of the information on google is difficult to understand. would someone help me with certificates/handshake stuff like that?

elder spoke
#

does anyone know how I would make it so windows defender doesn't hate my socket program when I turn it into an exe? Like to make it so I don't have to do any extra configuring of windows defender to make it fine for anyone to use if I send them the client?

upbeat forge
#

sign it

#

give the exe an author i think

high wing
#

Im setting a varible to my computer adress and how do i write it. This is not my adress
Do i write it like this
D5-K6-7A...
Or
β€œD5-K6-7A”
Or
d5-k6-7a
Or
D5K67A
Or a mix of the previous

storm saffron
#

@elder spoke you can try to make for example an outbound UDP request that the firewall will block

#

then the firewall will most likely prompt the user to allow python or your executable through

#

do you mean defender specifically or the firewall?

#

@high wing what do you mean

#

what is that code

#

and what do you mean 'setting a variable to my computer'

ember ledge
#

If I have two separate python scripts that I have listen on different ports, can my computer act as a separate server for both?

#

I want my raspberry pi 4 to reverse shell to my laptop so I can have a linux terminal on my laptop and also using that set up an MVQTT server

#

I've never tried having 2 sockets open on separate scripts before so I just want to know if it's feasible

storm saffron
#

yeah there's no problem if they're on different ports

stone delta
#

hey i have a question

storm saffron
#

ask away

stone delta
#

so how would you actually put a server on the internet?

storm saffron
#

hosted on your computer or similar?

#

host a server, then tell your router to allow connections in

#

then your server is on the internet, accessible at your public ip

stone delta
#

how would i tell my router

storm saffron
#

by port forwarding

stone delta
#

ok thanks πŸ™‚

storm saffron
#

that wasn't very detailed lol

#

feel free to ask more questions about this if you want to know more or actually set up a server

gleaming ivy
#

I wouldn't suggest port forwarding your router, use a remote host provider instead, like GCloud or AWS, first year should be free, if you provide a payment system. @stone delta

desert valley
#

does anyone know if its possible to re open this port after closing it?

#
    def __init__(self, PORT):
        self.thread1 = threading.Thread(None, self.run)
        self.Port = PORT
        ip_address = 'localhost'
        self.url = 'http://' + ip_address + ':' + str(self.Port)
        Handler = http.server.SimpleHTTPRequestHandler
        self.httpd = socketserver.TCPServer(("", PORT), Handler)

    def run(self):
        print('listening on: ' + self.url)
        self.httpd.serve_forever()
        print('Sever stopped')
        print('Port ' + str(self.Port) + ' should be available again.')


    def stop(self):
        print('Stopping server')
        self.httpd.shutdown()
        self.httpd.server_close()

    def start1(self):
        self.thread1.start()
#

I am trying to open the server for like 10 seconds, then close it, then re open it on the same port

merry jetty
ember ledge
#

b

indigo depot
#

@desert valley yes, just instantiate the server on a given port, like my_server = Serv(8080), then my_server.run(), do whatever you need to do for your 10 seconds, then my_server.stop(), then my_server.start() again when you want it up. as long as you don't create a new Serv class it'll still use the old my_server listening on 8080.

ember ledge
#

I'm basically just sending HEAD requests to an API with aiohttp with a random proxy every time, to test which proxies work. 99% of the connections raise one of these:

ClientResponseError, ClientHttpProxyError, ClientProxyConnectionError

Is the problem in my code or is it in the proxy?

#

ping me when replying

slender steeple
#

@ember ledge post code

ember ledge
#

ok

#
async def process_chunk(session, proxy, chunk):
  #proxy = 'http://' + 'xxx.xxx.xxx.xx:80'
  for data in chunk:
    headers = {'check': data}
    try:
      async with session.head(API_URL, headers=headers, proxy=proxy) as response:
        print(response.status)
        if response.status == 200:
          master_list.append(data)

    except ....
      .........

There are about 20 tasks of process_chunk running.

#

limit is TCPConnector(limit=50)

#
async def main():
  connector = aiohttp.TCPConnector(limit=50)
  async with aiohttp.ClientSession(connector=connector) as session:
    with open('data.txt') as data_f, open('proxies.txt') as proxy_f:
      tasks = []
      chunks = []
      
      ## Generate data and divide into chunks

      for chunk in chunks:
        proxy = next(proxy_f).strip('\n')
        proxy_url = 'http://' + proxy
        process_chunk_task = asyncio.ensure_future(process_chunk(session, proxy_url, chunk))
        tasks.append(process_chunk_task)

    await asyncio.gather(*tasks)
#

@slender steeple

#

and there are 800 datas

#

evenly split between 20 chunks

hexed ravine
#

Do any of you know how to build to build an ad-hoc network ?

#

Maybe with Arduino, Rpi or other

exotic bramble
#

What sort of communications are you looking to do?

pseudo beacon
ember ledge
#

i solve it thanks

ember ledge
#

whenever i play among us i get disconnected it says sent 6 pings that the remote server didn’t respond to and sometimes some ack’d thing...How can i fix this?

#

Ping if u know

hexed ravine
#

I'm participating in a competition.
I need to come up with some innovative ideas to make a safe college campus during this period of covid19

#

Do you guys have some ideas?

crystal cedar
#

Does anyone know of any unofficial Twitter API?

#

I checked at a variety of places. All of them point to the twitter API. I could find Instagram Unofficial API which needs only username and password of the user. Is there something similar for twitter or some other way to automate a bot to post tweets.

#

Someone told me that selenium can be used but websites are able to detect it and then put a captcha. Faced this when using selenium with outlook.

slender steeple
#

!rule 5

errant bayBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious or inappropriate. Do not help with ongoing exams. Do not provide or request solutions for graded assignments, although general guidance is okay.

slender steeple
#

wrong channel lmao

#

this is for internet networking

#

@ember ledge

ember ledge
#

Now I see it, my bad

#

The description didn't showed up which kind of networking.

undone cloak
#

Why does the recv function on the server side stop acting as a blocking call and starts receiving empty strings when the client program and connection ends ?

#

Isn’t it supposed to throw an error

storm saffron
#

depends how the connection ends i guess

#

what's your code

undone cloak
#

β€˜def receive(conn, addr):
while True:
data = conn.recv(512)
print(data.decode("utf-8"))
if data:
broadcast(data)’

#

That’s the server side

#

Client side is just connecting to the server and then sending a β€œhey” and then the porgram ends

#

β€˜def receive(conn, addr):
while True:
data = conn.recv(512)
print(data.decode("utf-8"))
if data:
broadcast(data)’
@undone cloak this keeps on spamming empty strings even after the connection from the client ends

undone cloak
#

Any help would be appreciated

plucky cave
#

hey everyone! i just wrote this today but if anyone is studying for the comptia A+ exam its just a little quiz on important ports and protocols. it's really simple and short but i hope it helps

slender steeple
#

minor suggestion: add some error handling so accidentally entering a non integer doesn't crash the program

tribal flower
#

^

ashen hearth
#

i was wondering how a change in a database could trigger a shell script to take place automatically on my computer

indigo depot
#

you mean you want the script to fire any time you make a change in the DB?

ashen hearth
#

thanks : )

plucky cave
#

will do! @slender steeple thanks for the input

rose viper
#

Simple and intuitive. REALLY like it otherwise..!! Always enjoy people pushing themselves to code small projects, way to go!

plucky cave
#

thank you @rose viper i appreciate your kind words. my last project was about 3 months ago so i decided its time to make something useful to actually help me study! I just started learning python in january and it has been very rewarding. Do you think it might be worth it to list that on my resume even though its so simple/short?

#

it also helps cause every time i have to run the code to test it, i get some practice in for my exam

#

two birds stoned at once hahaha

junior lion
#

Hello, how can I create a file Browser of another pc (socket) with Python?

ruby oasis
#

Hi everyone, I'm new to this community. I'm starting to approach the world of Python and Kivy and together with a friend of mine we are trying to develop a small app that allows you to send and receive text messages using the chat of a Minecraft server. Unfortunately online there are no tutorials about it even if I think it is possible as there are several similar apps on the play store. Could anyone help me? I guess you need special libraries (I tried with mcpi but it didn't work). I use VS Code on Windows, Python 3.7. Thanks in advance to those who will answer!

storm saffron
#

Like sending messages into a Minecraft server?

true raven
#
client.py:
def main():
    s = socket.socket()
    s.connect(("127.0.0.1", 8820))
    finished = False
    actions = ['rand', 'time', 'name', 'exit']
    while not finished:
        data = input("Enter data which you want to send to server: ")
        if data.lower() in actions:
            s.send(data.encode())
            reply = s.recv(1024).decode()
            print(reply)
            if data.lower() == 'exit':
                finished = True
        else:
            print("Invalid data.")
    s.close()

server.py:
def main():
    server_socket = socket.socket()
    server_socket.bind(("0.0.0.0", 8820))
    server_socket.listen(3)
    print("Server is up and running")
    finished = False
    while not finished:
        client_socket, client_address = server_socket.accept()
        quit = False
        while not quit:
            data = client_socket.recv(1024).decode()
            if data.lower() == 'time':
                t = time.localtime()
                reply = time.strftime("%H:%M:%S", t)
                print("Action Received: Sending Time...")
                client_socket.send(reply.encode())
            if data.lower() == 'rand':
                reply = str(random.randint(0, 11)).encode()
                print("Action Received: Random Number")
                client_socket.send(reply)
            if data.lower() == 'name':
                reply = "Server Name: Yuval's Server".encode()
                print('Action Received: Server Name')
                client_socket.send(reply)
            if data.lower() == 'exit':
                finished = True
                quit = True
                print("Exiting Server...")
                client_socket.send("Server Exit Call...".encode())
#

this works, but its quite counter productive imo.
is there any alternative to nested loops in the server.py? (im trying to achieve that the server wont just "shut down" after 1 task)

#

this is a practice question I got from school, if you're curious.

ruby oasis
#

@storm saffron yes

#

@true raven is this message for me? Excuse my ignoranceπŸ˜…

true raven
#

nono I was asking a question too :)
Im also new and if you have an answer id be glad for your help but I dont really have an answer to ur question :/

ruby oasis
#

I'm new too ... and unfortunately I don't have an answer to your question, Sorry :(

storm saffron
#

you shouldn' set finished i think

#

because you set quit when the user quits, but you also set finished

#

which ends the entire program

ruby oasis
#

@storm saffron can you help me? Sorry if I insist 😬

storm saffron
#

what's mcpi

ruby oasis
#

is a python library

sacred trench
#

hello is there a way to connect my app to my pc as a server?

#

like im making sth like "siri"

#

but i want to send the user inputs to my pc or server whatever kind for me to commit m achine learning

#

might as well input feedback to the user

rose viper
#

thank you @rose viper i appreciate your kind words. my last project was about 3 months ago so i decided its time to make something useful to actually help me study! I just started learning python in january and it has been very rewarding. Do you think it might be worth it to list that on my resume even though its so simple/short?
@plucky cave

#

I find that it never hurts to link the github because it opens the door to talk about your knowledge of git which most employers would appreciate. Sorry for the delay in response, have been AFK.

plucky cave
#

no problem at all! thanks so much for the insight

wraith grove
#

@sacred trench Yep, you'd have to make the server though

boreal igloo
#

good evening everyone!!

zenith roost
#

Good morning!

#

Could anyone please tell me how basic networking in python is done?

#

I know the basics of python till classes and I am interested for learning networking with python

sacred trench
#

@wraith grove how do I do that tho

thin sun
zenith roost
potent nymph
#

hmmm

wraith grove
#

@sacred trench Studying the basics of tcp/ip will help alot

#

here's a tutorial of the programming side of it

sacred trench
#

Ok thanks

#

Woah it’s a whole new level!!! Interesting

wraith grove
#

Yeah networking has a lot of stuff going on

#

Note if you are gonna be doing this on like your home PC, you will need to port forward

#

you can also get a VM from a variety of different cloud providers for like $3/month

sacred trench
#

Port forward?

#

Oh nvm

stuck charm
#

Hi I am a newbie to networking, going to attend a test for a server side engineer role. in a week or two The company expects basic computer knowledge (DSA,asynchronous I/O, databases, networks,etc) . I am confident about DSA. But apart from that I dont have much computer knowledge. Where should I begin,?what concepts should I look to cover?

gloomy root
#

Is the company aware of your lack of knowledge?

stuck charm
#

Yeah. The company is open for non cs major students as well

#

but they expect basic computer knowledge

gloomy root
#

fair enough

#

well full warning

#

you will not learn much in a week or so

#

Networking concepts in itself is massive

#

add that with AsyncIO which you'll want good knowledge of Python in general to use asyncio well
etc...

#

My best advise is get the Python knowledge down, read about networking concepts and tinker with a bit of asyncio doing some basic networking stuff, client/server system or something of the sort

stuck charm
#

Networking concepts in itself is massive
@gloomy root Yeah I can imagine that!

#

Yeah atleast i will try to learn some basics

#

in networking

#

any suggestions .. like any good book on networking?

gloomy root
#

not really but Real Python would be a good place to start:

https://realpython.com/python-sockets/
https://realpython.com/async-io-python/

In this in-depth tutorial you'll learn how to build a socket server and client with Python. By the end of this tutorial, you'll understand how to use the main functions and methods in Python's socket module to write your own networked client-server applications.

This tutorial will give you a firm grasp of Python’s approach to async IO, which is a concurrent programming design that has received dedicated support in Python, evolving rapidly from Python 3.4 through 3.7 (and probably beyond).

stuck charm
#

Cool! Thanks. Atleast somewhere to start I guess

obtuse flax
#

Hey guys! Is there anyone who has knowledge about video conferencing and online video broadcasting? I want to ask something about the algorithms that are used in it.

storm saffron
#

What kind of algorithms

obtuse flax
#

The algorithms which are used to send digital visual data from webcam or screen capture over internet

storm saffron
#

Well

#

Like what

#

Do you mean algorithm or do you mean program

icy hamlet
#

I am working on networking with a friend, and would like a basic introduction on how to set up a connection between two computers on different networks
I have understanding of sockets, and have been using a basic server-client model which can be found online
However, the logistics of setting up a connection has been a massive headache for both of us, and any help would be appreciated
Would opening ports on both networks be the right thing to do?

#

Thanks in advance πŸ™‚

#

And please @ me if anyone has an answer, or something I should consult - I may be afk at some points

storm saffron
#

What kind of connection are you thinking of @icy hamlet ?

icy hamlet
#

Just a simple server-client connection, between networks

storm saffron
#

Ah right, so like hosting a we server?

#

Web server

icy hamlet
#

Ideally p2p, I don't want to use a 3rd party connection (e.g, irc)

storm saffron
#

Idk why autocorrect doesn't like that

icy hamlet
#

Just direct connection

storm saffron
#

Do you know what UDP and TCP are

icy hamlet
#

Vaguely, but enlighten me

storm saffron
#

Well do you know what HTTP is

#

(I promise this is getting somewhere lol)

icy hamlet
#

I know I have been using TCP protocol over IRC

#

Couldn't tell you the details, but I understand it is a protocol with a fixed port number

storm saffron
#

Well it has a default port but basically it's how web requests are made on the internet

#

Any time you request a URL and get a response that's http

icy hamlet
#

Ah ok - port 80, right?

storm saffron
#

Yes, normally

icy hamlet
#

Got it

storm saffron
#

But you can use a different port if you specify one

icy hamlet
#

So it's just a request/response system

storm saffron
#

HTTP is built on TCP

icy hamlet
#

But you can use a different port if you specify one
@storm saffron Ah ok

#

HTTP is built on TCP
@storm saffron That makes sense

storm saffron
#

TCP isn't a way of requesting webpages, just a way of sending data back and forth

icy hamlet
#

Just a general protocol

storm saffron
#

So HTTP uses TCP to send the data it needs to send

#

Yep

#

UDP is like TCP, except it's not guaranteed to be reliable

icy hamlet
#

How can you implement TCP over two devices though?

#

The different networks thing is becoming a headache

storm saffron
#

So with TCP you send a message and keep trying until the other end confirms they got it

icy hamlet
#

How do you create a 'portal' so to speak?

storm saffron
#

And with UDP you just send it off and hope it gets there

#

Ah ok

#

So

icy hamlet
#

Got it - like ehlo in SMTP?

So with TCP you send a message and keep trying until the other end confirms they got it
@storm saffron

storm saffron
#

Afraid I'm not familiar with SMTP

icy hamlet
#

Just a mail server

storm saffron
#

Assuming you as a user haven't done any special port forwarding, when you make a request to your web server, your router spots that and when it sees the response, it knows to let it back in

#

Whereas other random packets are blocked because unless you've specifically port forwarded to let them in, they're probably malicious

icy hamlet
#

so you need to disable the firewall on some ports?

storm saffron
#

Yes

#

But specifically port forwarding sends incoming packets to a specific device on the local network

icy hamlet
#

That makes sense - so not all devices can read the incoming data

storm saffron
#

The other thing the router does automatically is when it knows a packet should be allowed back in, it also knows that it should go to a specific device

#

Do you know how local and public IPs work

#

IP addresses

icy hamlet
#

not completely, no

#

is one associated with your device, and the other with your router?

storm saffron
#

Yes!

#

Exactly

#

There aren't enough IP addresses for every single device to have a unique one on the internet

#

So your device connects through the router to the internet

#

Which means that when the response from a server comes back, it doesn't say in the message who it's meant for

#

Because the destination is the routers IP address

#

So the router has to guess based on who it saw make a web request previously

icy hamlet
#

So does the router have to redirect it to the intended location via port forwarding?

#

So the router has to guess based on who it saw make a web request previously
@storm saffron Huh, I never knew that!

storm saffron
#

You don't call it port forwarding in that case normally

icy hamlet
#

Does it ever get it wrong?

storm saffron
#

Yeah it's pretty cool

icy hamlet
#

It really is πŸ™‚

storm saffron
#

Well normally if it gets it wrong it just wouldn't know to send it back in

#

Do you play many online games

icy hamlet
#

That would make sense, I guess - so nothing bad would happen

#

I have played a few, yea

#

Some MMOGs

storm saffron
#

Have you ever seen it talk about a NAT type

#

Like open closed

icy hamlet
#

No, I don't think I have

storm saffron
#

So the problem is an online game doesn't work like a web server

#

Because the server might want to send a message to a client like 'you got shot at'

#

And the router might not let that in because it knows it isn't a response to something that got sent out

icy hamlet
#

Rather than the other way around, which would be a server-client?

#

So it has to act as both?

storm saffron
#

Well yes, one solution is to port forward on the client to force the router to send all the packets to your computer

icy hamlet
#

And that would carry it out directly?

storm saffron
#

But often routers will manage to figure it out, because even though it isn't a TCP connection, they can see that the UDP game traffic looks like a connection

#

So the packets coming in are probably ok

icy hamlet
#

So they can be sure they are secure

#

And they can pass through the firewall, so to speak

storm saffron
#

Yes firewall is slightly different

#

The router has a firewall which is the same thing as what does the port forwarding or packet blocking

#

But a computer also has a firewall

icy hamlet
#

But a computer also has a firewall
@storm saffron So, in practise, I might have to open ports on both computer and router to allow the traffic to pass?

storm saffron
#

Yes

icy hamlet
#

Got it

storm saffron
#

And btw I know this isn't really answering your initial question but I hope it's helpful

icy hamlet
#

it really is - I don't learn too much about the theory at school, so this is really great to learn

restive blaze
#

There is enough IPs if we used IPv6

storm saffron
#

Yep

#

There are enough ipv6 ips to index every grain of sand on earth I think

icy hamlet
#

Is IPv6 now standard? And how would you update old devices to deal with it?

storm saffron
#

The ips that are running out are ipv4

#

Which is still widely used

#

But ipv6 is slowly becoming more popular

icy hamlet
#

Yeah @storm saffron , 256^6

#

Which is ~2.8147498e+14

#

So probably enough πŸ˜‰

storm saffron
#

Plenty of toasters

#

I think the model of having your devices behind a router is likely to stick around though

#

Because it's quite convenient

icy hamlet
#

It shouldn't be the responsibility of the device to direct internet traffic in that way, I agree

#

And keeping routers means the same standard can remain across all connections - without a change being made for some, or different protocols being established

storm saffron
#

Also isn't really compatible with a modern way of connecting to the internet

icy hamlet
#

in what way @storm saffron ?

storm saffron
#

It used to be that you'd use a modem to connect from your computer to the exchange

icy hamlet
#

but that's seriously antiquated

storm saffron
#

But now you have so many computers in the house and you use modern fibre or other broadband providers

#

There's no way realistically to connect things like laptops or phones to your fibre lol

icy hamlet
#

Ethernet is inconvenient, too

storm saffron
#

But anyway you wanted to know about connecting devices together

icy hamlet
#

yeah

#

it's hit so many roadblocks

storm saffron
#

Is this two python programs

#

And do you think from what I've said that you want to use UDP or TCP

icy hamlet
#

Two python programs, and since packets should be safe, TCP should be good

#

I think???

#

@storm saffron

storm saffron
#

Sure that sounds good

icy hamlet
#

:sighofrelief:

storm saffron
#

So you'd need to port forward and open the firewall on both computers and networks

icy hamlet
#

Ok - that explains why it hasn't been working

#

My friend has struggled to open the network on his end

slender steeple
#

ngrok is another option

icy hamlet
#

ngrok @slender steeple ?

slender steeple
#

it lets you tunnel a tcp connection through an external server

icy hamlet
#

oooooh that looks useful

slender steeple
#

the only minor issue you may have is that the ip and port will change everytime you run it

icy hamlet
#

that's frustrating - is there any way to allow it to read the ip/port automatically each time, to run automatically? @slender steeple

storm saffron
#

I'd say if you're new to networking then it'd be good to do it the basic way even if it's harder for users to use

icy hamlet
#

ok, ill give that a shot

#

i wasn't intending it to be user-friendly yet - that's a whole universe away rn >_<

#

thank you so much @storm saffron

storm saffron
#

Np I hope some of that was helpful

#

Let me know if you have any other questions

icy hamlet
#

Thank you so much - you are so knowledgable, do you mind if i dm you in future?

storm saffron
#

Sure

#

And I'm not that knowledgeable I've just spent a lot of my time wrestling with this

placid tree
#

hey guys I've a simple question. What does sharing a printer in a domain controller mean?

Does it mean that the printer isn't a network device but can connect to the domain controller over usb and can be shared over the network without any network interface?

The reason I'm asking is that DC has control over who can access a printer, how is that possible?
Do these printers usually have a user interface to be controlled?

restive blaze
#

Printer is published in Active Directory

foggy badger
#

Probably not, that would be a very silly way to connect a printer. 98% of the time printers are networked and have a webgui which some people can logon to see toner status etc. Usually there are AD groups that decide who can print and where.

#

You can send print jobs directly to a network printer. But a computer (doesn't have to be a server can also be a windows 10 machine or anything really) can also share a printer on the network. So then print jobs are send to that computer first. So depends on the setup really.

sacred trench
#

Hi does anyone know if it’s possible to host a home pc as server with socket

#

Is it safe

#

I’ve written a server script for client and host

#

But I’m not sure cuz I remember someone telling me to use a VM

#

told*

normal siren
#

help

#

im using openvpn

#

and it says openvpnapi.vpn not found

#

i installed openvpn

#

and pypi

#

for it

calm ingot
#

Any references or explainatipns on how to create your own automatic openvpn network that you can access that’ll let you stream network traffic through?

#

Pretty much a vpn programmed in python

tough hemlock
#

anybody know if in python there is a way to listen in on a http post request being done?

ember ledge
#

@tough hemlock Yes there is, using the requests module

slender steeple
#

no

#

he means mitm

#

i think

tough hemlock
#

what I am trying to do is see the data being transmitted during a post request

slender steeple
#

you can if its http and not https

ember ledge
#

So for example:
response = requests.Session().post(link, data=...)) print(response.status_code)

slender steeple
#

@ember ledge he wants to MITM a http request

ember ledge
#

This works for me

slender steeple
#

not make a http request

ember ledge
#

Oh

tough hemlock
#

sorry let me explain further

slender steeple
#

wait are you the one sending the original post request and you just want verbose info?

#

or do you want to intercept a post request from a diff program

tough hemlock
#

I am already making the http post request sending a file to an api but I am want to see how much data (not the actual data or the response) has been sent so I can create a upload progress bar

slender steeple
#

ah

#

i misunderstood

tough hemlock
#

sorry I should have clarified a bit more earlier

slender steeple
#

idt requests can

#

requests is synchronous

tough hemlock
#

that is what I am thinking too after all my research

slender steeple
#

huh apparently you can

tough hemlock
#

hmm... interesting they are using a progress bar for load/queuing up the file to be sent (or am I reading that wrong)

ember ledge
#

Do you guys know how to check if a session is closed when using the requests module?

#

Plus what does a closed connection even mean? After I close a session I can still do requests in that session

tough hemlock
#

@slender steeple I will give it a try and let you know

#

They are very short vids and explains it very well. I was watching them last night with investigating the upload problem.

ember ledge
#

@tough hemlock Thanks for the vids but they sadly don't cover the closing of a session

versed wing
#

hi

#

python noob here

#

networking a field in particular that i lack severely in

#

how should i go about starting to learn it?

#

from the barebones?

#

is there a roadmap i could follow?

storm saffron
#

what kind of thing do you want to learn

tall basin
#

is there a way to send email from smtplib, using variable font, colour, and other design parameters...?

#

def send_mail_(args):
#print('mail')
from_addr = args['From']
password = args['Password']

to_addr     = args['To']
cc_addr     = args['CC']
bcc_addr    = args['BCC']
    
with smtplib.SMTP('smtp.gmail.com', 587) as server:
    server.starttls()
    server.login(from_addr, password)

    SUBJECT = args['Subject']  
    TEXT = args['Text']  
    
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    message     = "From: %s\r\n" % from_addr
    message    += "To: %s\r\n" % ",".join(to_addr)
    message    += "CC: %s\r\n" % ",".join(cc_addr)
    message    += "Subject: %s\r\n" % SUBJECT
    message    += "\r\n" 
    message    += TEXT

    to_addr    = to_addr + cc_addr + bcc_addr

    #print('message_compiled')
    #print(message)
    server.sendmail(from_addr, to_addr, message)

This is the code which I'm using rt. nw.

versed wing
#

what kind of thing do you want to learn
@storm saffron
Just want to be proficient at learning it atleast to a level where I am comfortable in web dev or automation

wicked knot
#

amateur hour here: I'm testing connectivity using socket.connect_ex(), but I can't for the life of me find the meaning of the return values anywhere in case of a connection failure

#

I must be missing some keyword in my searches

#

aha nevermind, gotcha

#

return values are to be used with 'errno' to find the meaning

ember ledge
#

is it possible to change your ip and mac address in python because i was under the impression that i could not do that ?

storm saffron
#

changing your ip doesn't really mean anything

#

it depends whether you mean on the internet or LAN

#

and some network adapters let you use a custom or randomised mac address

#

but 'in python' doesn't really have anything to do with it

ember ledge
storm saffron
#

none imo

obtuse tree
#

hey dude

#

!rule 5

errant bayBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious or inappropriate. Do not help with ongoing exams. Do not provide or request solutions for graded assignments, although general guidance is okay.

storm saffron
#

the whole graded assignments thing

#

i think because it ends up leading to low quality questions along the lines of 'do my homework for me'

#

but if you're confused then i'd say 1 or 3 or neither

#

probably leaning towards 1

faint hemlock
#

@normal rapids we can help you learn what you need to know to complete assignments, but we can't, for example, help you answer questions on a test while you're taking it. It's a rule because we don't want to be a platform for cheating.

smoky estuary
#

[WinError 10049] The requested address is not valid in its context

cli.connect(("0.0.0.0", 9026))
#

Not sure wtf is going on

#

i have a server up and everything

slender steeple
#

you can't connect to 0.0.0.0

#

that's only for listening on all interfaces

#

for connecting you need to specify a real ip

#

@smoky estuary

smoky estuary
#

but that works for all my other programs

#

oh i used gethostname() for my other programs

smoky estuary
#

A single python file can handle being a socket client and server right?

#

(Lemme give some context here)
Say i have a server, Server1 and it is outside this py file but still on my PC

Then i have a client, client1 which is in this py file
Then i have another server, Server2, which is in this py file

Then i have another client, client2 which is outside this py file but still on my PC

#

^would the py file with the client and the server be able to fill both positions or do i need threading or smth

tall flower
#

Yes it can

pale steeple
#

hello i am new to networking

#

can anyone direct me to some good tuts or anything i can start with

ember ledge
#

@pale steeple they teach the basic and some advanced fundamentals you may want to learn for free on Youtube. They cover networking, cyber security, system administration, Operating systems, etc. I find this really useful and started out learning with this. Each video is roughly 7 hrs long and covers variety of aspects in these fields for free by google. If ur willing to dedicate time and want to persist with networking, i recommend browsing some udemy courses if you feel like you want to go the long haul (they cost money but they are inexpensive), there are many CompTIA certificates that are valued overratedly by the IT industry that include networking

pale steeple
#

@ember ledge Thanks a lot. I'll check it out.

ember ledge
#

anytime πŸ‘

ember ledge
#

Anyone here familiar with AWS or cloud hosting ( mainly EC2 instance)??

#

Need some help

#

please tag me if u know

ruby isle
#

hi there, not sure if this is the right channel ... but im trying to upload to gdrive, visiting speedtest.net i get 324.67mbps download, and 11.96mbps upload, however, when i am using python (pydrive), or rclone, im getting 0.76mbps (95mb in 74 seconds, and upload to gdrive via rclone), am i not understanding the conversion or is there a bottleneck somewhere?

south abyss
#

Speed tests are done in megabits, actual upload speed are usually measured in megabytes. 1 byte is 8 bits, so that 12mbit upload is just over 1 megabyte per second

#

Therefore 95MB in 74 seconds is about accurate @ruby isle

karmic falcon
#

about sockets: is it better to keep a single socket instance to a server or create a new connection everytime I need to use?

storm saffron
#

depends what you're doing

karmic falcon
#

If you know the amount of data to be received, then you can keep reading from stream until you read all bytes to be received.

#

your protocol does not inform you the amount to be transfered?

#

did you make the server too?

#

or just the client side?

#

Well I would recomend to define your own message-based protocol on top of TCP in order to differentiate message boundaries.

#

as said in the stackoverflow post

#

That way the server can send in a header the amount of data to be transferred

#

then your client can know when to keep reading from network

#

since recv doesnt guarantee to receive all data at once

rotund basin
#

anyone have any preferred libs for parsing custom bit fields? talking like... 7 bit or 10 bit uints, so not aligned cleanly for libs like bitstruct.

#

naturally can do it manually / roll my own, but i thought perhaps folks had a favorite tool

#

i spend most of my time in JS so wasnt as familiar

candid narwhal
#

does anyon know if there is a way to build ARP packets without using scapy ?

storm saffron
#

well yeah you can send on ethernet layer with sockets

#

but it's a bit more painful

candid narwhal
#

yeah this looks very painfull lmao

#

imma try anyway, thanks for the clue g

analog umbra
#

flask vs django

#

im a beginner

analog umbra
#

ping me

ember ledge
#

@analog umbra

analog umbra
#

lol

ember ledge
#

πŸ˜‚ πŸ‘

gleaming tendon
#

Guys I have an api key but when I use it in the code it is not working...error message says β€˜ You must use an api key to authenticate each request...’

storm saffron
#

can you show your code

#

i used to have a macro to type that you know

slim prism
#

I hope this is the right place, is there anyway to check with Python if a certain website is visited?

#

ping me please

storm saffron
#

wym 'is visited' @slim prism

#

detect when a website is visited?

slender steeple
#

@ember ledge personally, i think flask is better than django for beginners since theres a lot less complexity

#

and less "magic" going on behind the scenes

dawn goblet
#

p

dim apex
#

sku

analog umbra
#

thanks hmm

slim prism
#

@storm saffron when you go onto a website

#

Is it possible to detect it

calm ingot
#

Could you be more specific?

#

Detect the client side traffic?

#

Or detect that you just went to that website?

winged river
#

I'm working on a project with sockets

#

in my client file I do:

SERVER_IP="localhost"
SERVER_PORT=9324
with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
            s.connect((SERVER_IP,SERVER_PORT))

server.py

PORT = 9234        

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind(("", PORT))
        s.listen(5)
        print("Program started")
        conn, addr = s.accept()
        
        with conn:
            print('Connected by', addr)
            while True:
                data = conn.recv(1024)
                if data:
                    print("data:",data)
                if not data:
                    continue
#

Although I specified a port in both files,

#

it outputs:
Connected by 127.0.0.1:58128
Why is that??

gloomy root
#

because a client will use a OS assigned port by default

#

if you send that client multiple times you'll probably notice that the remote Port will be different every time

winged river
#

yeah

ember ledge
#

@ember ledge personally, i think flask is better than django for beginners since theres a lot less complexity
@slender steeple ahCool

winged river
#

Is there a way to make this more efficient/without a while True: loop?

with conn:
            print('Connected by', addr)
            while True:
                data = conn.recv(1024)
                if data:
                    print("data:",data)
                if not data:
                    continue
                

west sedge
#

just a quick question, is there some sort of a failsafe for the error 10054 (the connection was forcibly closed from the remote host)? I get cut a lot and then the python code stops

storm saffron
#

you can usepy try: <network activity> except socket.error: print("waaa error")

velvet rapids
#
try: 
  <network activity>
except socket.error as e:
  if e.errno == 10054:
    #stuff 
  else:
    raise
storm saffron
#

ah nice

lusty ermine
#

hey guys

#

how does p2p work?

modest pebble
#

P2P is a type/category of protocol, not a protocol itself

#

It is used for protocol that will allow a back and forth connection between one client and one server

north badge
#

hi folks. Any users of the websockets library in here? I'm wondering if it's possible to assign some state to a given websocket connection during the process_request handler?

gusty lance
#

does anybody know how to send a http request with a proxy using the socket module?

tribal frost
#

@modest pebble I don't want to burst anyone's bubble, but p2p is serverless

#

if it is implemented on a server then it is abstracted

#

p2p is opposite of client server and is client based

#

servers can act as clients is what you were probably meaning

wheat trench
#

@analog umbra flask is a bit more flexible, but i think both are equally good. so it all depends on you, what to use.

analog umbra
#

ok

viral sundial
#

does any one know how to do network service discovery using zerconf

tribal frost
#

hi

harsh bay
#

I'm using requests to download a bunch of images from a text file. Here is my code


image_list = open("images.txt", 'r', encoding="utf8")

for count, line in enumerate(image_list):
  split_line = line.split('_')
  message_id = split_line[0]
  timestamp = split_line[1]
  url = ''.join(split_line[3:]).replace('\n', '')
  filename = url.split('/')[-1]

  output_filename = f"./images/{message_id}_{timestamp}_{filename}"

  try:
    response = requests.get(url, stream=True)
  except Exception:
    print(f"Server returned {response.status_code}, skipping image.")
  else:
    with open(output_filename, "wb") as out_file:
      out_file.write(response.content)
      out_file.close()
      print(f"Downloaded {output_filename}.")```
However, a lot of the images turn out to be 223 or 192 bytes (yes, those specific numbers) and invalid, when they are valid URLs and images such as this one: https://cdn.discordapp.com/attachments/195278167181754369/335246741706244097/CRP838_01-IMS-en_GB.png
#

However as seen in the screenshot it turns out to be 223 bytes in size for no reason. The script exits with no warnings or errors. What is happening with requests and how can i mitigate this?

#

Keep in mind the invalid images only amount to about 1/3rd of all downloaded images, the rest are valid and completely downloaded.

#

I also don't think this is a problem with large image sizes because this one is about 828kb and there are images that are 6-7MB in size that have downloaded successfully

#

Also, these are the same images every time I run the script. The exact same images are invalid so that rules out any circumstantial or time-specific server error

slender steeple
#

response.raise_for_status()

#

check if no http errors occured

harsh bay
#

Okay, I will try

#

Btw is using the try except thing good practice? I have not seen any other examples using it and I only use it because I can't seem to catch a 200 outside of it even suing response_code

#

Oooooh, thank you

#

:D

storm saffron
#

i bet the error images have text content

#

ye

#

so that's probably an http response

harsh bay
#

Yeah lol

#

I think it was writing the contents of the errors into the files and assigning the files a mimetype of png/jpg

#

There are a surprising amount of files that are forbidden access

peak tapir
#

Is anyone using parallel-ssh to transfer files from one system to another?

drowsy shard
#

Has anyone worked with python and Tor? I need to have a server that receives a small .txt or some bytes, but i dont know if i need ftp, tcp...?
I am lost, and since its a very specific thing, maybe someone could help. Ty