#networks

1 messages · Page 24 of 1

storm saffron
#

where the client polls the server for messages

shy pebble
#

most things use websockets, which essentially create a server on the client and use that

sleek drum
#

Is python or html best to start?

narrow oak
#

totally depends on what you want to do and if you prefer frontend or backend, but this is not the right channel.

ember ledge
#

Whats the right channel for beginners sorry to ask here

pure raft
#

Hello everyone.. what is the best way to write a python code which verifies if tab completion is working fine in a router

sacred trench
#

hi is there a way to host without port forwarding

crimson mirage
#

need a clear explanation of
what is a header
in api

prisma cobalt
lusty forge
#

I don't know if this question is relevant, but for some reason when I boot up Linux (Ubuntu), it does not connect to my wifi adapter (TP-Link T4u) at all. It is not broken as it works perfectly fine when I boot it up to Windows 10. My guess is the adapter is not not compatible with Linux or the driver is outdated.

storm saffron
#

have you installed a driver

ember ledge
#

how to make python client and server side so i can screen it to a port and connect via putty

lusty forge
#

I have not

#

although its fully updated on windows

storm saffron
#

yeah the windows driver won't have anything to do with linux

#

i imagine you'll have to look for a driver for that wifi card yourself

#

looks like they have a linux installation guide

lusty forge
#

Okay so I'm following the instructions and it's telling me to install 'make', and for some reason, its saying that 'make' has no installation candidate.

storm saffron
#

have you run sudo apt-get update

#

that makes sure you actually have a package list available locally

lusty forge
#

it's saying that its failing to fetch some of the features

storm saffron
#

are you connected to the internet

lusty forge
#

No

#

that's why I'm trying to get a driver

#

since my wifi adapter doesn't work with Linux

ember ledge
#

there a way i can make my own os

#

for my router using python

prisma cobalt
dreamy kelp
#

@lusty forge

#

You can use your phone

#

USB tethering

lusty forge
#

Actually that might work

storm saffron
#

or ethernet surely

stark pine
#

Hi Guys

#

I recently started using the sockets library

#

But I have some doubts

#

The first one is:

#

I want to create a program that has a server and a client

#

In the server

#

Will be a Sqlite3 database

#

And I need to the client can acess it

#

But, I don't know how can I send a message from the server specifically to the client who sent a specific message

#

Does anybody knows how to do this?

twilit tartan
#

hello, im wondering where can i learn the basics or the fundamentals of networks and networking

lusty forge
#

@dreamy kelp It works! Thank you so much, I have been trying to configure my WiFi to Linux forever.

dreamy kelp
#

You're welcome!

#

@lusty forge What's your wifi?

#

Like, what's the chip?

#

if it's broadcom you'll guaranteed get help from me

#

Since I've dealt with broadcom chips before in Linux

lusty forge
#

It's a TP Link T4U

dreamy kelp
#

I'll look into it

lusty forge
#

On a side not, why does Linux go hay-wire with certain wifi adapters?

#

Is it because some adapters are closed source?

young blaze
#

Super new on python... Tips please, I know some networking and have some computer skills but I need to know at least one lenguaje program and I have decided that phynton is the one

#

Youtube has a lot of content but sometimes is overwhelming and you kind of get lost

ember ledge
#

same

slender steeple
#

ew w3schools

#

ngl its kinda bad

#

!resources

errant bayBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

slender steeple
#

@ember ledge

#

@young blaze

ember ledge
#

I want to create an API for Authentication in Flask is there any tutorials or articles can you suggest

fossil lodge
#

any ideas how I could test that proxies work? I wouldn't want to ping google for example by testing each proxy

vital glacier
#

hello, can anybody please explain to me how I can send a signal to 2 raspberry pis over wifi?

#

establishing communication and sending signals for i/o

#

for example if a button is detected on first raspberry pi it sends a 1 or a 0 to a second raspberry pi

frozen drum
#

@ember ledge you can create a custom protocol in windows by modifying the registry

#

look up x-scheme-handler or whatever equivalent there is for your system

ember ledge
#

I built a little script that kinda give me some control over what devices connect to my Access Point.

The original goal was to get message notifications when someone I knew connected, like a door bell when friends drop by but with a text.
It works ok seem to have a few issues.

I’m looking for more ideas to add to this script I feel like I’ve only just begun making a AP device manager, there must be a million things I could do I haven’t thought of and I’m looking for input if anyone has an idea to add.

This is what it looks like right now

https://paste.ofcode.org/VWUMsVJWcsAzsUcJ7eASep

smoky estuary
#

Whats the most optimal family and type for sending larger transmissions of data over a socket

prisma cobalt
#

oof

robust barn
#

can anyone tell me if im doing this formula right?

#

n(n-1)/2 n = 4

#

4(4-1)/2

#

4(3)/2

#

12/2

#

6

storm saffron
#

looks good to me

sterile zephyr
#

Hello, anyone knows how to write logging to shared network files?

marble pollen
#

Has anyone worked on building a rtmp server in python?

winter nimbus
#

how to not send traffic through vpn in python with socket with udp protocol?

coarse pendant
#

what is a tcp client?

#

Can anyone explain with diagram

proper aspen
#

Gentlemen: What's the go to message delimiter/framer package in python? Zmq? A way of transmitting complete message frames over inet without building up from sockets.

#

With the requirement of no external message broker service, or being limited to web-requests. Just a sanity-wrapper around TCP

modest fulcrum
#

Maybe some big brainer could help me set up my router to allow connecting to other devices on the network? ie. connect to a server on the same network using it's private IP address

ember ledge
#

I can @modest fulcrum

#

What u need?

modest fulcrum
#

@ember ledge I have an Archer C7, trying to telnet to a TCP server running on another device but I can't, can't even ping it.

#

Not sure how to proceed 😄 I'd be happy to hop on voice and share my screen and go through the settings

ember ledge
#

Do u know how to bind something like on server, ip port etc?

modest fulcrum
#

Yep

#

Everything that's server-side I can manage, the particularities of networking escape me ;D

ember ledge
#

Ah, good old tcp servers

#

Its on Lan or? @modest fulcrum

modest fulcrum
#

Yeah, on LAN

#

It's my desktop running a TCP server and trying to connect from a windows device on the same network

ember ledge
#

Uh, u need to bind user

#

I can help u

#

With conn

#

Ill write code for conn on user

#

It should work

modest fulcrum
#

Nono, this should be networking specific, the same server works on the network in my office

#

Same OS, same everything, just different network

ember ledge
#

Oh

#

Its harder then i thought

real cypress
#

@modest fulcrum what do you mean can you be more specific

ember ledge
#

Hello I'm trying to get an old Zelda the golden Kingdom server started for some friends and me. I used these files here:
https://github.com/LostSoulFly/Zelda-Golden-Kingdom/tree/Testing

The thing is when I try to start up the ver .70 server I get the runtime error 339: Component RICHTX32.OCX or one of its dependencies is not correctly registered.
I tired to search for the file but cloudn't find it.
The other thing is when I try the starter.exe it always says "Please run this program as an Admin" even if I'm running it as one and with my kaspersky security disabled.

one friend managed to get around the "RICHTX32.OCX" problem but then I think it needs a DLL setup or smth idk really.

robust barn
coarse pendant
#

@robust barn lol

#

hi

#

I've a problem

robust barn
#

?

#

im a new guy so idk alot

ember ledge
#

I want to build a Home-server

#

Which os is best?

#

for it?

storm saffron
#

for what purpose

#

media?

#

or as a file share

ashen ruin
#

im an engineering major wanting to do something interesting in my break

vital glacier
#

Is python socket programming platform independent?

#

does it use winsock or unixsocks?

gloomy root
#

most of it a OS independent because the dependant stuff is usually under the hood

#

but there are certain specifics that can change between OS for example Asyncio's event loop supports and selectors

storm saffron
#

yeah definitely be aware of os differences

#

but the concepts involved in sockets and most of what you write can be platform agnostic

ember ledge
#

Hey can I find someone who can assist with my secure decentralised backend?

#

I'm working on and off on it

#

But I'd like to pick up the pace a bit more

tulip nymph
#
1. s.bind(("",9000))
2. s.bind(("localhost",9000))
3. s.bind(("192.168.2.1",9000))
4. s.bind(("104.21.4.2",9000))
#
  1. Lets any connection bind to port 9000, 2. let's only the local host to bind to port 9000, 3. let's only 192.168.2.1 bind to port 9000, and 4. let's only 104.21.4.2 bind, to port 9000.
#

Is that correct?

storm saffron
#

no, the first element in the tuple is what address to bind to

#

i.e. serve on

#

so localhost serves only on the local computer

#

192.168.1.x (your LAN ip) serves only on the local network

#

and 0.0.0.0 binds on all interfaces

tulip nymph
storm saffron
#

it will accept connections from everywhere, effectively

#

any way a packet could get to your computer, if you're listening on 0.0.0.0 you will get that packet

tulip nymph
#

I thought "" meant it accepts connection from everywhere

#

so does 0.0.0.0 have the same effect as ""?

hoary sorrel
#

Yes.

For IPv4 addresses, two special forms are accepted instead of a host address: '' represents INADDR_ANY, which is used to bind to all interfaces, and the string '<broadcast>' represents INADDR_BROADCAST. This behavior is not compatible with IPv6, therefore, you may want to avoid these if you intend to support IPv6 with your Python programs.

tulip nymph
#

So then is what I said for IPv4 or IPv6?

hoary sorrel
#

"" and "0.0.0.0" both only work for IPv4, and mean exactly the same thing.

tulip nymph
#

Ahhh.

#

Thank you

tulip nymph
#

Is there a place where I can learn networking? I've just been wandering the internet and I'm not sure which resource I'm supposed to use

astral smelt
# tulip nymph Is there a place where I can learn networking? I've just been wandering the inte...

Well I just completed a course in college on it. Try "Kurose and ross: Computer networking A top down approach". You'll learn the Networking layer by layer. 7 layers that is. This book is great. And also try these videos, I guess they could help, it did to me 🙂 https://www.youtube.com/playlist?list=PLo80JwUm6hSSwGLJmS_quaeJgx9SILLiI

errant bayBOT
astral smelt
#

I need help with VOIP project. I was able to do a one way communication. I want to be able to do it the two way. Idk how to use threading to make it possible, I've tried it but I don't have much experience with it and hit a wall. I'll add client and server code for one way.

#
#client
import socket
import pyaudio

chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 10240

host = 'Local netwrok IP address' #enter your Local netwrok IP address of the machine that is running the server.py code
port = 50000
size = 1024

p = pyaudio.PyAudio()

stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, frames_per_buffer = chunk)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
print ("Connected!! You can now speak")

while True:
    data = stream.read(chunk)
    s.send(data)
    s.recv(size)

s.close()
stream.close()
p.terminate() 
#
#server

import pyaudio
import socket

chunk = 1024
pa = pyaudio.PyAudio()


stream = pa.open(format = pyaudio.paInt16, channels = 1, rate = 10240, output = True)

host = 'Local netwrok IP address' #enter your Local netwrok IP address of the machine that is running the server.py code
port = 50000
size = 1024
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host,port))
sock.listen(5)

client, address = sock.accept()
print ("Server is now running\n=======================")


while 1:
    data = client.recv(size)
    stream.write(data)  
     

client.close()
stream.close()
pa.terminate()
prisma cobalt
ember ledge
#

can anyone plz help me with http.client module requests to get the root document of a webpage?

#

@hoary sorrel ?

hoary sorrel
#

I'm gonna go to bed soon, but I can try for a minute. It's usually preferable to use the requests package from PyPI instead, as it's much easier to use

ember ledge
#

ill look into that

ember ledge
#

guys, how can i see the status of a port that isnt on my current ip? i mean, on windows, running netstat, shows the ports linked to current ip. But i know for other ips there are other ports oppened

storm saffron
#

how do you know

#

and by opened do you mean on your router

ember ledge
#

yes, and i know cuz i opened some port for some games, but my pc ip is dynamic and it changed

#

i use to have it static, but idk why i swapped it

blazing axle
#

i'm kind of new to sockets and server programming. Is there any way I can use AWS to set up a server that's always listening by uploading some python code?

#

Also do you guys know any good resources to learn more on this topic

opaque hedge
kind furnace
#

@blazing axle what do you want the socket to listen for? I.e End Goal / problem you are solving ?

subtle scaffold
#

How am i able to find the port that is connected to the certain ip i am looking at?

astral smelt
#
receive_thread = threading.Thread(target=receive_server_data).start() send_data_to_server() 

Could you explain what this block of code is doing?

#

How am i able to find the port that is connected to the certain ip i am looking at?
@subtle scaffold

S = socket.socket(socket.AF_NET, socket.SOCK_STREAM)
Hostname = s.gethostname()
HostIP = s.gethostbyname(Hostname)

Please correct me if I'm wrong. I'm new to socket programming.

subtle scaffold
#

@astral smelt do i just put all of that into a ide?

#

sorry im new to this

blazing axle
blazing axle
#

@kind furnace essentially the goal is to output a video stream with different overlays based on whos watching

astral smelt
#

@astral smelt do i just put all of that into a ide?
@subtle scaffold
You must be aware why I took the "s" variable.
Now try "host = s.gethostname()" and print the host variable. You'll get bunch of stuff, in which you'll also be able to see the port number and the IP address. Now, s.gethostbyname() used to get the IP address only. Google about both of them, gethostname and gethostbyname method.

analog glade
#

Hello Team
hope you are all well
I need help to make little python program
I have 3 list
u = ['a','b','c']
v = ['a','b','c','d']
w = [1,2,3,4,5,6,7,8,9,10,11,12]
and I need below desire output
output =
a a 1
a b 2
a c 3
a d 4
b a 5
b b 6
b c 7
b d 8
c a 9
c b 10
c c 11
c d 12
do we have any trick in for loop ?

subtle scaffold
#
import socket

server = input('server: ')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def pscan(port):
    try:
        s.connect((server, port))
        return True
    except:
        return False
for x in range(1,26):
    if pscan(x):
        print("port",x,"is open")
    else:
        print("port",x,"is closed")
#

@astral smelt afters some research this is what i came up with

#

i made a successful port scanner based on user input

#

what do you think about it?

unborn dock
#

Hello guys.
I am working on some docker containers, Where there is a "main" nginx host that then proxies to other nginx hosts

#
server {
    listen 80;
    server_name mcaq.me www.mcaq.me files.mcaq.me dev.mcaq.me priv.mcaq.me;

    location / {
        proxy_pass http://mcaq:8080;
        proxy_redirect http://mcaq:8080/;
        proxy_set_header    Host                   $http_host;
        proxy_set_header    X-Real-IP              $remote_addr;
        proxy_set_header    X-Forwarded-For        $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto      $scheme;
    }
}
#

This (above) is the main nginx container

#
server {
    listen 8080;
    index index.html index.php;
    server_name mcaq.me www.mcaq.me;
    root /code;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass localhost:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
#

This (above) is an example of one of the sub-nginx containers

#

The main nginx server is being controlled by certbot after running, so is actually listening on 443 ssl

#

It shows the 8080 port, which I don't understand

#

It works as expected

#

I've tried different things like using proxy_redirect, but I am struggling to find a solution, or understand what the problem is

#

Any advice, or if you need more infomation, let me know. cheers!

astral smelt
#

i made a successful port scanner based on user input
@subtle scaffold great, can you share it with me? Just DM me, if you could

hoary sorrel
#

Networking is just the general term for making two processes talk to each other over a network... Like whenever you want to access a server over the internet, for instance.

ember ledge
#

Hello i'm having a Error with my program. i'll leave the source code if needed.

#

Its saying

#
  File "mac_changer.py", line 25, in <module>
    change_mac(options.interface, options.new_mac)
AttributeError: 'NoneType' object has no attribute 'interface'
```
subtle scaffold
#

Leave source code

ember ledge
#

there

#

please tell me why the error occurred too.

#

@subtle scaffold

ember ledge
#

nvm i got it

errant bayBOT
#

Hey @hollow yarrow!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

hollow yarrow
#

#bot-commands

void pawn
#

I want to write an application for my bluetooth headset, how can I do this to check the charging status

#

qcy t5 model

slow trench
#

how do i protect the data that i send over socket4

#

socket

#

not 4

#

help

tardy totem
#

I just want to confirm the arp command in the cmd. Basically, it used to identify the IP and MAC addresses of the devices on your network which mean u know who is on the network? Correct me if I’m wrong

copper swan
#

I am using sockets to create a chat application

#

but i am getting this error "OSError: [WinError 10049] The requested address is not valid in its context" when i put in my public ip

storm saffron
#

do you want to encrypt it so it cant be spied on?

#

spyed

#

spied

#

who knows

reef jacinth
#

Want a challenge during the Holiday season? Participate in the New Year Solve, where you get the opportunity to solve this year’s most groundbreaking challenges. From the world of Health, to Climate to Finance, participants can choose one category and create a solution that can help millions. If you want to read more about these categories, swipe to read on how technology is impacting these sectors! Compete for a prize pool of $50 with your friends all from the comfort of your own home. And you heard it right, t his is completely FREE! https://forms.gle/i4q3iAkJjvopyGru7

velvet rapids
#

huh?

winter nimbus
#

help

#

how to create a udp socket without listening?

hoary sorrel
winter nimbus
#

Yes but I don’t want to recv any packets, I only want to send out packets

hoary sorrel
winter nimbus
#

But when I do sock.recv(99) it recieves the packet

#

If i don’t release it the memory will grow larger and larger

hoary sorrel
#

Release what? How?

#

recv creates a new bytes object. If you keep it, it takes up room. If you keep a lot of them it could take a lot of room...

#

Also you said you don't want to receive any packets, then you said you're calling recv... I think I'm missing something here.

winter nimbus
#

when someone send me a packet, the system will capture the packet and store it somewhere

#

and if I don't use recv frequent enough, those packets will build up in my system

#

how do I tell the system to drop all packets that is sent from someone?

hoary sorrel
winter nimbus
#

No

#

But I called sento

#

And it should bind automatically

hoary sorrel
#

Then it shouldn't even be possible to receive, AFAIK. I don't think you can receive UDP packets if you never called bind()

winter nimbus
#

yes you can

#

idk

#

lemme test that

#

yeah

#

yes you can

#

I just tested it

#

using sento() will give you a port

hoary sorrel
#

Yes, it does, but you shouldn't be able to receive on that port.

#

That port is open for sending only.

hoary sorrel
#

hm, nope, I'm wrong. I just tested, you can receive on that port.

#

TIL

#

well, alright, general knowledge then: the maximum amount that could ever be sitting around waiting for you to recv it is the size of the socket's receive buffer. By default that's probably about 200 kb, if you're on a Unix system, and you should be able to shrink it further using setsockopt to set the SO_RCVBUF option - the minimum on Linux appears to be 128 bytes.

#

I don't think there's a way to completely remove the receive buffer for a socket.

novel halo
#

guys, anyone with understanding about game serving with python?

#

i have my game idea ready, just need a server

#

saw some tutorials but nothing is making me understand

#

I do understand the very basics, ip:port, sending and receiving information, the problem start with the loops, how to interpret the messages sent and received

winter nimbus
#

yes

#

use tcp

storm saffron
floral acorn
#

I have to learn about networking for my exams :()

broken kiln
#

Would you guys suggest getting my Comptia network+ cert

stray wave
#

hello everyone I am looking for help in my python project, can anyone guide me ?

late pike
#

is there a pre-written library for clients to send images to server w sockets?

main fable
#

Hi guys, I have aws t3 medium centos machine. I have installed jenkins on that machine and it is running. But i am not able to access the jenkins on my local browser using : http://publicipofmachine:8080. Can someone please help in this

unborn dock
#

@main fable have you opened your IP firewall to that port?

#

@late pike why do you need to use sockets?

late pike
#

The purpose of the code isn't just to send images

#

but also images

unborn dock
#

I don't think there's a specific library, but it isn't too difficult to do with the sockets module specifically. Have you tried that?

late pike
#

I tried, I encoded the image to base64 and tried to send it to the server. But I got confused when having to calculate how many bytes do I want to recv

#

but yeah I think I can do it myself

#

I was just curious if there is such a library

unborn dock
#

I don't think there is, but I'm sure you will be able to find a example to help you. I can have a look for you if you need a hans

#

Hand*

primal plaza
#
msg = 'Thank you for connecting'
client_socket.send(msg)
```This gives warning Expected type 'bytes', got 'str' instead
Why not str though?
hoary sorrel
#

UTF-8 would be the most common choice these days. If that's what you want, you can do client_socket.send(msg.encode())

primal plaza
#

so is b'' and encode('ascii') same thing?

hoary sorrel
#

b'' is an empty byte string. encode('ascii') is a method call you could make on a string to encode it into bytes according to the ASCII encoding. If the input string was empty, it would generate an empty byte string.

#

b'' is equivalent to ''.encode('ascii') - though the empty string is encoded the same in every string encoding, there's nothing special about ASCII

primal plaza
#

alright thx

hoary sorrel
#

You almost certainly want to use UTF-8 instead of ASCII

#

Unless you know you need some specific other encoding, UTF-8 is by far the sanest encoding to default to these days.

silent flicker
civic wyvern
#

I want to send image data over sockets. Can I just do this:

image = open(dir,'rb')

and than serialize it using json?

upbeat badge
#

.

hoary sorrel
civic wyvern
#

But I can store the .read() contents in an object, serealize the object, send the object to the remove, and then unserealize at the other side?

hoary sorrel
#

What do you mean by "serialize"? If you need to use JSON, it makes things a little bit more complicated.

#

JSON doesn't have a way to represent binary data, so you'll need to encode the binary data into some text format like base64 before sending it, and the receiver will need to know to undo that transformation.

civic wyvern
#

I have an app written in python that sends items over a network (shopping items). I want to keep things object wise simple, so packing everything into an object, including the image would be really nice

#

@hoary sorrel

hoary sorrel
#

like I said, then, you'll need to encode the binary data as text before JSON encoding it. So, something like:

import base64
import json

image_file = "some_file.png"
with open(image_file, 'rb') as f:
    image_bytes = f.read()

image_base64_text = base64.b64encode(image_bytes)

message_dict = {"image": image_base64_text}
message_json = json.dumps(message_dict)
sock.sendall(message_json)
#

and then the remote side would need to do the reverse of that - deserialize from JSON, extract the "image" key, deserialize from base64 using base64.b64decode(), and then it has the raw binary bytes of the image again, which it could write to disk or whatever.

civic wyvern
#

@hoary sorrel nice! thanks! If I recall correctly, json only takes dicts to serialize? If you pass custom object, object.dict() return will be used?

hoary sorrel
#

I'd be very surprised if it used obj.__dict__ instead of obj.keys() and obj[key], but I'm not positive.

#

!e easy to find out...

import json
class C:
    def __init__(self):
        self.x = 10
    def keys(self):
        return ["a", "b"]
    def getitem(self, key):
        return 42
obj = C()
print(obj.__dict__)
print(json.dumps(obj))
errant bayBOT
#

@hoary sorrel :x: Your eval job has completed with return code 1.

001 | {'x': 10}
002 | Traceback (most recent call last):
003 |   File "<string>", line 11, in <module>
004 |   File "/usr/local/lib/python3.9/json/__init__.py", line 231, in dumps
005 |     return _default_encoder.encode(obj)
006 |   File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode
007 |     chunks = self.iterencode(o, _one_shot=True)
008 |   File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode
009 |     return _iterencode(o, 0)
010 |   File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
011 |     raise TypeError(f'Object of type {o.__class__.__name__} '
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/burivolexo.txt

hoary sorrel
#

nope, looks like it doesn't even use the mapping protocol, it just expects a dict.

#

that makes sense, considering the way it has to handle recursion.

civic wyvern
#

So I will have to write a method manually to go from object to dict and from dict to object?

hoary sorrel
#

In my example above, I didn't have a method for that - I just did message_dict = {"image": image_base64_text}

#

I guess you could make that a dedicated method, but I think it depends a lot on what else you're trying to do.

civic wyvern
#

I have an item object that stores some other data too, so would be handy if I could create a dict from the object and vise-versa with ease

hoary sorrel
#

well, you can. in the case of your image, you're just setting one key in the dictionary to a base64-encoded version of the binary data of the image. If you want to do that in a dedicated function, you can.

civic wyvern
#

@hoary sorrel thanks! you're awesome

civic wyvern
#

@hoary sorrel may I ask another question?

hoary sorrel
#

sure

civic wyvern
#

I want to be listening for a server reply constantly except for when I want to send to the server. I already did research, is it true that it would be best to use non blocking sockets?

hoary sorrel
#

yes - unless you know that you'll only send to the server at specific times, in which case you could get by with blocking sockets with a timeout set.

civic wyvern
#

Thanks, my academic python course did not even mention sockets 😑

hoary sorrel
#

you may find that asyncio is the easiest way for you to do what you're trying to do, FWIW

civic wyvern
#

Any asyncio socket lib that you recommend?

#

I know asyncio basics, but no real asyncio socket lib

#

I see, asyncio has support for sockets inplemented

hoary sorrel
civic wyvern
#

@hoary sorrel but can I use sync socket server side and async client clientside?

hoary sorrel
#

yep; the client and server are completely independent - how one of them interacts with the socket doesn't affect how the other one does.

civic wyvern
#

nice! thanks a lot! I am restructuring my entire project. Just so it becomes a bit cleaner. You're the best

ember ledge
#
import socket
import threading

host = "0.0.0.0"
port = 1337

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(100)
print(f"Listening on: {host}:{port}")

clients = []

def commander():
        
    while True:
        conn, addr = s.accept()
        print(addr[0] + " connected!")
        command = input(">> ").encode()
        conn.send(command)

while True:
    threading.Thread(target=commander, args=()).start()

hey, im trying to do that it'll require me to enter a command everytime

#

but it does just once

#

any ideas?

fair dock
#

@ember ledge so once you entered a message and it has been send the script stops right?

ember ledge
#

ya

fair dock
#

maybe you can add a statement for is_active in the def commander before calling your first while True. So it nows something is still active and the script shouldn't close unless that is set to inactive what you call when the client disconnects from the server. Add the is_active = False in the beginning and then go is_active = true. If this doesn't work you can always use the "Try" function

ember ledge
#

something with threading is going on there tbh

#

i lost my files of that

fair dock
#

do you have a server running for your chat system?

ember ledge
#

ye

fair dock
#

Do you have a receive function so you can see each others messages?

ember ledge
#

ye

#
while True:
    data = s.recv(1024).decode()
    print(data) 
#

i just need server.py continue to send messages

#

not just stop once its sent

fair dock
#

Remove the while True from threading.Thread(target=commander, args=()).start(). maybe this works

ember ledge
#

nope

fair dock
#

il send you mine maybe you can use some parts def sendmessage():
while True:
if stop_thread:
break
message = f'{nickname}: {input("")}'
else:
client.send(message.encode('ascii'))

receive_thread = threading.Thread(target=receive)
receive_thread.start()

write_thread = threading.Thread(target=sendmessage)
write_thread.start()

sturdy owl
#

ahh finally an active community

#

🍉

molten abyss
#

Why is networking so hard 😢

#

At least ... why is it impossible to debug

spare bison
#

Hi Guys! I am network engineer and wanted to learn python, I am a complete noob in python ..Just joined python discord channel can someone advise me on where to start? Thanks

molten abyss
#

I built on top of the code they provided.

spare bison
#

Sweet..Thank you @molten abyss

ember ledge
molten abyss
#

I would suggest asking this question in one of the help channels found in the Available Help Channels category

ember ledge
#

Ok man thanks

molten abyss
#

On that note; Would anyone happen to know how to create a new thread when a connection has been established on a python server?

#

Basically, I am trying to get my server to handle multiple client requests asynchronously

hoary sorrel
molten abyss
#

Yah, I found out that I have to use threads. I now need to figure out how to adapt my code to permit threading. I don't have perfect formatting, as I taught myself python yesterday, which is what is making this so challenging blobtired

hoary sorrel
#

it's a great language to know. keep at it 🙂

errant bayBOT
#

Hey @queen herald!

It looks like you tried to attach file type(s) that we do not allow (.exe). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .svg, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .webm, .webp, .flac, .afdesign, .m4a, .csv.

Feel free to ask in #community-meta if you think this is a mistake.

sacred trench
#

Pls @ me if you know thanls

hoary sorrel
#

!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.

sacred trench
#

ono ok

#

sporry

native oar
#

Hey, I'm having issues with using proxies and the requests module

#

requests.get("http://ip-api.com/json/", proxies={'http://': "username:password@ip:port"} )

#

When I make that request it still outputs my ip, thanks

storm saffron
#

Does requests have any way to restrict a url to a certain domain

frozen drum
#

parse the url yourself and verify it before doing the request?

hoary sorrel
storm saffron
#

yeah ok just wondered if there was some like

#

well

#

completely prevent it from making requests outside of a domain

#

but this works fine i guess

plush cargo
#

Hey! i'm new here.

hoary sorrel
storm saffron
misty raft
#

is my understanding of the following correct: the total number of IP address available is called the IP Address Space (about 4 billion of these). These are then broken up into 3 major groups (i realize there are 5 and not 3) class classes, Class A, B and C. Each class has a certain number of IP address in them. Each of the classes is then broken up into further subgroups called networks which each holds a certain number of IP addresses?

hoary sorrel
#

that was correct, once upon a time, but Class A, Class B, and Class C aren't really a thing anymore, and haven't been for decades.

#

now, a network is defined by an IP address and a subnet mask, instead of the size of the network being implicit based on the class.

misty raft
#

oh ok but the concept still applies?

#

as in the ip addresses are broken up into networks which are then broken up into subnetworks?

#

like an IP address with a subnet mask for 255.0.0.0 is in the network (group) of 255.0.0.0?

#

i guess i mean the network that are represented by the first octet*

hoary sorrel
#

The subnet mask tells you how big the network is. 255.0.0.0 tells you that the first 8 bits of the IP address (the entire first octet) are part of the network address. So if an IP address like 10.1.2.3 has a subnet mask of 255.0.0.0 it belongs to the 10.0.0.0 network, which includes 16777216 possible addresses. If it has a subnet mask of 255.255.255.0, then it belongs to the 10.1.2.0 network, which contains 256 possible addresses.

misty raft
#

gotcha gotcha and that's for subnet masks with 255 or 0 ---> refers to the network. The subnets with says 255.255.252.0 means the network represented by the first 2 octets and the subnetwork of the next 6 bits?

#

because 255.255.252.0 = 11111111.11111111.11111100.00000000?

hoary sorrel
#

right. so given an IP address like 253.253.253.253 with a subnet mask of 255.255.252.0, the network address is 253.253.252.0 (because 253 & 255 == 253, and 253 & 252 == 252)

misty raft
#

you mean 253 and 253 == 255?

#

and the third 253 == 252?

hoary sorrel
#

No - I meant what I said.
255 . 255 . 252 . 0 is the network mask
253 . 253 . 253 .253 is the IP address. You get the network address by bitwise-AND'ing these things together.
SO the network address is:
(255 & 253) . (255 & 253) . (252 & 253) . (0 & 253)
which is 253.253.252.0

misty raft
#

hmmmmm

#

i understand the first 2 octets

#

isn't the subnet mask just a map for which bits are responsible for the network ID or the subnetwork ID and which are for the Host ID?

hoary sorrel
#

right - the third octet, 252, is 11111100 - so the first 6 bits of the 3rd octet of the IP address are part of the network ID, and the last two are part of the host id. And all of the last octet is part of the host id.

misty raft
#

ok gotcha and since it's only 6 bits and not 8 bits it gets a special name of subnet right?

#

like subnet ID

hoary sorrel
#

no - not really. "subnet" is short for "subnetwork", which is a term that you were already using earlier.

#

Network A is a subnetwork of network B if network A's host address range falls entirely within network B's host address range

#

so, 10.1.0.0/255.255.0.0 is a subnetwork of 10.0.0.0/255.0.0.0

#

because 10.1.0.0/255.255.0.0 contains host addresses from 10.1.0.0 through 10.1.255.255, and 10.0.0.0 contains host addresses from 10.0.0.0 through 10.255.255.255, and everything in the first set falls inside the second set

#

or, to put that a different way, network A is a subnetwork of network B if it has more network mask bits set than network B, and if you masked off those extra bits you would get network B

#

is that making any sense?

#

!e ```py
import ipaddress
a = ipaddress.IPv4Network("10.1.0.0/255.255.0.0")
b = ipaddress.IPv4Network("10.0.0.0/255.0.0.0")
print(a.num_addresses)
print(b.num_addresses)
print(a.subnet_of(b))
print(b.supernet_of(a))

errant bayBOT
#

@hoary sorrel :white_check_mark: Your eval job has completed with return code 0.

001 | 65536
002 | 16777216
003 | True
004 | True
hoary sorrel
#

if you were to chop 10.0.0.0/255.0.0.0 into 256 equal sized chunks, one of those chunks would be 10.1.0.0/255.255.0.0, so 10.1.0.0/255.255.0.0 is a subnet(work) of 10.0.0.0/255.0.0.0

misty raft
#

hmmmmm

#

i think it does hang on

#

ok i got that par

#

part*

#

basically something with more 1's in the subnet mask is the subnetwork of something with less 1's in the subnet mask right?

#

i.e. 255.255.0.0 is a subnetwork of 255.0.0.0

hoary sorrel
#

you also need to consider the network address

misty raft
#

well yes

hoary sorrel
#

then yes, as long as you realize that.

misty raft
#

assuming the network addresses make sense

#

like 192.x.x.x is not a subnetwork of 10.x.x.x regardless of the subnet masks right?

hoary sorrel
#

if the two networks are equal up until the shorter of the two network masks, then the one with the longer network mask is a subnetwork of the one with the shorter one.

misty raft
#

like 192.x.x.x is not a subnetwork of 10.x.x.x regardless of the subnet masks right?

hoary sorrel
#

right.

misty raft
#

hmmmmm

#

that makes sense then

#

it is a bit tougher to visualize

#

but it's better now

#

thank you very much @hoary sorrel

misty raft
#

know much about port forwarding?

#

yeah haha i drew something like that on my notebook when trying to explain it to myself

hoary sorrel
#

that shows how each time you add one new 1 bit to the network mask, you effectively divide the old network into two new ones.

#

(each half the size of the old)

#

sure, I know some things about port forwarding.

misty raft
#

ok so essentially i have a server program on my raspberry pi. i managed to connect to it from my laptop using a client program (all programs written in python). The whole point of this is to then have the server run another prgoram that controls my servo motor (that's already written)

#

I then realized the only reason i was able to connect to the server using the ip addresses that i used in the programs were because they are both within the same LAN and that if my laptop were not connected to the same router, then it would be trying to access the server on my rpi from the WAN

#

because, again, the whole point is i want to connect to this server from anywhere in the world, so port forwarding is a possible solution to this?

#

the architecture goes: press a button on an app that i create (from anywhere)---> sends signal to server on rpi that's always listening ---> server starts the program to control the servo

hoary sorrel
#

well, yeah, but - doesn't sound like a good idea to do that, unless you're very confident or very careful. If anyone anywhere in the world can send input to your script, and there's any type of input to your script that could cause the servo motor to overheat, or things like that, you can cause physical damage this way.

#

but yes, configuring your router to allow inbound connections on port 9000 (or whatever) and send them along to your RPi's port 9000 when they come in will work.

misty raft
#

ok yeah so plenty of people have told something to that extent of being careful. Is that because i'm basically exposing that port to the world unprotected?

hoary sorrel
#

you're achieving exactly what you said you wanted to do, allowing anyone in the world to connect to that port on that machine and send whatever they want to it. So, how will your program handle it if 100,000 computers connect at once? Or if they send you invalid messages? or if they tell your servo to spin as fast as it can for as long as it can? or if the Linux kernel running on the raspberry pi includes a vulnerability in its TCP stack that allows someone making specially crafted TCP packets to cause it to execute arbitrary code?

misty raft
#

hmmmmm that makes sense, so how can i limit it so that only i can access that port from anywhere in the world?

hoary sorrel
#

¯_(ツ)_/¯

#

build some sort of authentication system and be very convinced that you got it right.

#

at that point you're into security territory, not networking territory.

misty raft
#

that actually makes a lot of sense

#

i'll reflect on that going forward, thanks man, i appreciate your help. Is there any way i can like rate you or something? I'd like to give you 5 starts or whatever is the max

#

or maybe a mod you want me to put in a good word for you?

hoary sorrel
#

hah, nah, thanks but no such thing needed. 🙂

#

glad to help.

misty raft
#

well if there is such a thing let me know @hoary sorrel

#

!close

civic wyvern
#

is SHA1 hexdigest save to use?

#

I send the hexdigests over tcp connection where they are stored in yaml.safe_dump files

grizzled gulch
#

safe as in free of collisions?

#

Generally no (known attacks against it), but unless you're the target of a nation state, you're probably okay.

storm saffron
modest pebble
#

SHA1 is pretty trivial to force, even if you aren't working on a really sensitive project you shouldn't use it

storm saffron
#

yeah depends on what you mean by 'safe to use'

#

if it's for the same purpose as md5 then like

#

ok

modest pebble
#

MD5 is considered crypto secure though, isn't it?

gloomy root
#

MD5 carries the same trivial force issues

#

too fast to make hashes with and massive lookup tables make for ez brute force

modest pebble
#

Fair enough

slender steeple
#

for checksums just use one of the sha-2s

ember ledge
#

Hello. can anyone tell me how to make the most basic multi user chat prompt?
Is this possible with command prompt
I am creating a MUD engine and part of that is allowing users to see each others text input.
I need to have a working multi user environment as soon as possible. Any idea how long it would take to make it coding 8 hours per day?

civic wyvern
#

probably very dump question, but is there a data limit on tcp sockets in python?

storm saffron
#

data limit how

civic wyvern
#

I have constructed a giant dict consisting of multiple images in base64. Can I sent them over tcp without problems?

storm saffron
#

how giant

#

and why not use http to get rid of some of the painfulness of large transfers

#

if they're really large

civic wyvern
#

about 700 kilobytes per transfer

#

@storm saffron

storm saffron
#

ah right

molten abyss
#

Assuming that the connect, isConnected, and disconnect functions work as intended, could someone explain why this function won't execute the second print statement if the client fails to connect to the server?

def test(self, port):
        conn = connection()
        connected = False
        print("connecting...")
        server = conn.connect(port)
        
        connected = conn.isConnected()
        conn.disconnect(server)
        print(connected)
        return(connected)
#

Better yet, here is the connect function:

 def connect(self, port):
        server = socket.socket()
        server.settimeout(5.0)
        host = socket.gethostname() #Might not be a bad idea to put into a config file
        print(f"host: {host} type: {type(host)}")
        print(f"port: {port} type: {type(port)}")
        server.connect((host,port))
        connection.conn = True
        return(server)
civic wyvern
storm saffron
molten abyss
#

It just gives me a connection refused error

storm saffron
#

on the server?

molten abyss
#

On the client. I'm basically doing a port test.

storm saffron
#

well it failed to connect so it raises an error

molten abyss
#

hmm

storm saffron
#

on the server, is it just not getting to the second statement?

#

print statement

molten abyss
#

Ah, I see what you're saying. Sometimes I forget that my application doesn't crash since it's linked to a gui

#

Ok, so I need to do a try,catch then

storm saffron
#

yeah, just catch that specific error

molten abyss
#

Would you happen to know the error? ie, what to put on the except line?

storm saffron
#

you can catch whatever error it throws

#

so in this case probably something like sockets.ConnectionRefused

molten abyss
#

right, but how you format it

#

ConnectionRefusedError

#

ah, kk

storm saffron
#

a bit like this

molten abyss
#

ok, so that's not the attribute

storm saffron
#

in that case, i know that TypeError is built in

molten abyss
#

So it's a typeerror?

storm saffron
#

not in your case

#

my example was to show that i tried the error behaviour

#

saw that i got a typeerror

molten abyss
#

Oh, I know

storm saffron
#

then knew to catch a typeerror

molten abyss
#

I just need to know what specifically I need to put after the except

#

like verbatum

storm saffron
#

ah so the error class is ConnectionRefusedError if that's what the error message said

#

however

#

it's in the sockets module

#

annoyingly python errors don't actually tell you the namespace of the error

molten abyss
#

ikr

storm saffron
#

let me look a sec

molten abyss
#

im seeing from stackoverflow that socket_error will work

civic wyvern
#

Is a raspberry pi zero suitable for a tcp socket server? What are your opinions?

molten abyss
#

ok, that didn't work

#

Got it!

#

It's socket.error

#

lol

storm saffron
#

oh right

#

yeah i cant find it in the docs

#

which is

#

weird

molten abyss
#

Now if only I can figure out this buffer problem >.<

#

Then I'll be finished with my CTF 😄

storm saffron
#

weird

molten abyss
#

ikr

storm saffron
#

so what's the buffer problem

molten abyss
storm saffron
#

boop

molten abyss
#

I tried changing the buffer size, but that didn't work

storm saffron
#

are you sending more than 1024 bytes of data

#

cause it will wait for the timeout if it doesn't receive enough

#

but i thought it doesn't error with the timeout

#

just returns the data you wanted

molten abyss
#

2 strings

storm saffron
#

ah right so why is the timeout a problem

molten abyss
#

That's what I am trying to figure out

#

😆

storm saffron
#

what goes wrong

molten abyss
#

uh

#

hold on

#
Screen:  login
host: DESKTOP-293494 type: <class 'str'>
port: 12345 type: <class 'int'>
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1884, in __call__
    return self.func(*args)
  File "C:\Users\user\Documents\Python\CustomCTF\client\start.py", line 149, in <lambda>
    login = Button(window, text = "Login", font=32, padx = 10, command=lambda: loginHandler(eUser.get(), ePass.get(), result))
  File "C:\Users\user\Documents\Python\CustomCTF\client\start.py", line 172, in loginHandler
    response = log.check(user, password, server)
  File "C:\Users\user\Documents\Python\CustomCTF\client\login_client.py", line 19, in check
    rec1 = s.recv(2048).decode()
socket.timeout: timed out
storm saffron
#

weird i didn't think it errored on timeout

#

huh

#

ah ok so

#

set the timeout as 0, then if no data is available you won't receive any but if that happens you can just check next time

#

also be aware you can't necessarily guarantee that the data will arrive in a sensible way

molten abyss
#

Except the fact that it times out every time

storm saffron
#

if you transmit the username then password, you'll receive them all at once

molten abyss
#

^^^^

#

I was actually about to bring that up

storm saffron
#

yeah but if you set the timeout to 0 it will keep the waiting data until the next call

#

i think recvline is a thing

#

or recv_until

#

so you could use newlines to delimit your data

#

and transmit username:password or something

molten abyss
#

so here's this code snippet:

  #success = False;
        s.sendall('login'.encode('utf-8')) 
        #while not success: #Loops through until successful login 
        if not user or not password: #Fail-Safe
            #print("Please enter a username and password.")
            return(("Please enter a username and password.", 0))
            #continue
        s.sendall(user.encode('utf-8'))
        s.sendall(password.encode('utf-8'))
        
        rec1 = s.recv(1024).decode()
        rec2 = s.recv(1024).decode()

Lets say that the 'login' message gets send, then the user ("John") gets sent.
What happens is that the server receives them concatinated, "loginJohn"

storm saffron
#

yep

#

cause it's all just a sequence of characters on the wire

#

doing

molten abyss
#

*shock

storm saffron
#
sock.send("Hello")
sock.send("Hi")
``` is the same as ```py
sock.send("HelloHi")```
molten abyss
#

Even if I have 2 receivers?

storm saffron
#

yep

molten abyss
#

shock

storm saffron
#

cause the first call tries to read 1024 bytes of data

#

whatever that is

#

it has no idea that two python function calls have caused the data to be written

molten abyss
storm saffron
#

now switch from surprised_pikachu to pithink

#

bigbrain time

#

you need a way to stop that happening!

molten abyss
#

I actually have quite a bit of rewriting

#

Also, how does one split text at a character?

storm saffron
#

.split on a string

#

for example

molten abyss
#

ah

#

ty

#

I started learning python 2.5 days ago, so I don't know all of the syntax yet

storm saffron
#
"hello".split("e")

is ["h", "llo"]

#

learning python 2.5

#

or

#

2.5 days ago

molten abyss
#

2.5 days ago

storm saffron
#

thank god lol

molten abyss
#

I'm learning Python 3.9 ?

#

3.7?

storm saffron
#

noice

molten abyss
#

The most recent release

storm saffron
#

much better python 3, 2.5 days ago than python 2.5, days ago rolf

#

all good

molten abyss
#

lol

#

python 2 is disgusting

#

Comparing the code, it's just like ... what is this, C?

#

b/c python2 has a lot of similarities to C, ngl

storm saffron
#

imo python3 is like python2 but less worried about being a proper programming language

#

so they fully support unicode strings by default

#

bytestrings are different

#

raw_input vs input

#

just a load of sensible changes that get rid of the ways in which python 2 tried to be non pythony

molten abyss
#

It's so funny. I used to hate python, mainly because I hate R, and I had to use Python for my AI class, which I hated.

storm saffron
#

ah rip

#

we get a lot of data scientists here

#

maybe """""""""""""data scientists""""""""""""""""" is more appropriate

molten abyss
#

But man, now that I am doing networking, python is so fun

storm saffron
#

good!

molten abyss
#

I'm not a data scientist and I hope to never be one

#

Though a good portion of my major is data science

#

Even if it's only high level

storm saffron
#

eh they're useful skills

#

but yeah i've never actually wanted to learn any of it rolf

molten abyss
#

you say that

#

I will probably, never in my life, try to interpret and transform a csv

storm saffron
#

interpret maybe

#

but yeah

#

the statistics specific stuff is like

#

why

molten abyss
#

Well

#

I do like stats

storm saffron
#

sure

#

me too

#

but not just writing data processing code for no reason

molten abyss
#

tru

molten abyss
#

@storm saffron Let's say I do: split = "msg".split(":")
Will this throw an error?

storm saffron
#

no, afaik it will return ["msg"]

molten abyss
#

oh. bet

#

ty

storm saffron
#

lte me test it

#

yeep

#

also note that

#

which is a bit interesting

#

if you're not expecting it

molten abyss
#

Oh ye, u learn that in intro to CS

storm saffron
#

ah nice

molten abyss
#

It's the way an array is set up

#

|0|1|2|3|4|5|

#

Like that, and the | is the edge case

storm saffron
#

ah sensible

#

i've never really learned programming in a class

#

the practical parts at least

molten abyss
#

Ah

#

yah, if you work with pointers, things get very finnicky

storm saffron
#

yeah

#

well

#

pointers are easier in C than python cause in python if you're doing mutability then that's fine

#

but the moment you start wanting to thinking about pointers to things it becomes a lot more tricky

molten abyss
#

Yah, @storm saffron I'm still getting the timeout error

#

grr

#

I think I actually made it worse 👀

#

Oh wait, hold on. Sorry, I think I know what's happening

storm saffron
#

Sorry going to bed atm, feel free to DM me if you have any more questions about this

#

I'll answer when I can

molten abyss
#

kk. Np

native oar
#

Is there anyway to print the origin of the request? Using request module

lost relic
#

Can someone please tell me a cheap way to host a Flask project temporarily?

hallow jetty
#

@native oar idk maybe ```py
import socket
import request

#Howwever there is defintely a better way, because theis just gives you the IP of the current machine the script is running on

me = socket.gethostbyname(socket.gethostname())

#

imma do more research on this

storm saffron
storm saffron
somber plover
#

How do I send an instance of a class from a server to a client using sockets

storm saffron
#

that's vert tru=

#

oops

#

very tricky

somber plover
#

I meant pickle*

storm saffron
#

since the other end has to know exactly how to turn it into an instance of the object at the other end

#

ah right

#

well pickle still isn't great because it's very insecure

somber plover
#

I don’t mind

storm saffron
#

if your program is unpickling everything it gets sent, anyone can run any code they want on your computer

somber plover
#

Like with what I have right now

#

I don’t mind

#

Because it’s just for a school project

#

With what I have right now all I am sending are basic strings

#

when my client connect to one another they each get dealt a different instance of my ‘card’ class

#

But I want them to all have been dealt cards from the same deck

#

I don’t know what to do to my code in order for them to be dealt cards from the same deck

ember ledge
#

hey, does anybody know something about upnp sockets?

sleek hemlock
#

can I make amultiplayer game with python

#

maybe a fps game would be cool, but i dont know any networking libraries or resources

#

are there any good resources for game networking?

molten abyss
#

Is it possible to transport data from javascript to python through an open socket?

#

And when I say possible, I mean feasible

#

I know it's doable on node, but idk about normal js

hallow jetty
hallow jetty
#

If anyone codes in Raw Sockets. I am particularly working on editting IP headers, and generating correct checksums.
Somebody please help

hallow jetty
#

Anything on Networking and codding sockets in python3 hmu because i do client socket coding.

Heres a trick to easily send encoded strings in python3

import socket

destination_addr = 10.1.1.1 # What u want

Port = 15 #Open UDP Port ( Any )

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Str_send = input("Data to send>  ")

s.sendto((bytes(str_send), (destination_addr, port))

#

Thats how u easily send encoded strings in python3

marsh fern
#

Hey guys how can I block making requests to a domain from my PC? But I want requests to go when I use a proxy.
I tried blocking domain names in /etc/hosts. But it is blocking proxy requests also.

marsh fern
#

Is it possible to block a domain name using iptables?

#

If yes, will I be able to make request to that domain using the proxy from the same machine/container?

hallow jetty
hallow jetty
#

You dont have to scrutanize the /etc directory and it will save you time

marsh fern
#

getting this iptables v1.6.1: no command specified

hallow jetty
#

sudo apt-get install iptables -y;

somber plover
light zealot
#

Can somebody share the basic code for client.py and server.py for connecting 2 devices?
I'm very new to networking, I've tried visiting certain websites,repositories but none worked for me

#

Any help would be appreciated

#

Pls guys help me out

lost vapor
#

Not really sure where to ask this so please point me to another channel if this isn’t the right one.

I’m building a scraper for a website. This website has the following section in their ToS:
You agree not to use or launch any automated system, including without limitation, "robots," "spiders," or "offline readers," that accesses the Service in a manner that sends more request messages to the servers in a given period of time than a human can reasonably produce in the same period by using a conventional on-line web browser.
Am I correct in assuming that scraping is allowed as long as it does not send more requests than a normal user would? If so, how many requests would you say a normal user can reasonably send?

gloomy root
#

Generally its such a blanket term its risky regardless of what you use as the number

#

1 request meh sure

#

but other than that its pretty vague for a reason

lost vapor
#

A request a second? A request every 5 seconds? I’m not so much concerned about the legal side of things as I am about upsetting the website devs and having my IP banned.

light zealot
storm saffron
gloomy root
exotic solar
exotic solar
#

Also, what IP address should I use to connect two computers via sockets? I tried using my public IP address, but the external client produced an error that the target machine (this computer) actively refused it, I'm assuming that this is because of a firewall. How should I get around it?

Also, one of the computers is connected via wifi, the other s connected via ethernet

#

Hmm, looks like my firewall isn't turned on anyways, yet it's still blocking connections.

#

I restarted the server, but I'm getting OSError: [Errno 49] Can't assign requested address with the public IP

#

I changed the IP address to my local IP address and I can get the server running now

#

and the client works!

#

🥳

ember ledge
#

whats the default type of auth in requests?

storm saffron
#

the requests module?

storm saffron
#

by default your router drops all incoming packets that aren't part of an outbound connection

sleek hemlock
#

How can I make a multiplayer game

#

in python

#

using pygame

#

and some networking thing

#

library/module

#

I know some basic networking stuff

#

but i dont know where to get started

#

and help is appriciated

#

thanks

storm saffron
#

have you made a game in pygame already

slender steeple
#

@ember ledge default appears to be http basic auth

#

if by default, you mean this requests.get('https://api.github.com/user', auth=('user', 'pass'))

#

though there are many other ways of authorization

#

such as oauth and jwts

ember ledge
#

thank you

light zealot
fast drum
light zealot
#

Thanks!
😄

frozen sedge
#

hi, does anyone have experience with pfsense ?

#

if so please @ me, i have been trying to figure out why my network gets really high ping when downloading something.

#

i have tried using queues /limiters and the same issue comes

#

it did get to a point where if i was downloading the ping was fairly ok (about 50ms when pinging to google) when i usually get about 15 without any downlaods going on

#

but when i joined a discord voice call as an example, ping went really high

#

have been trying for days, have no luck, if anyone could help or knows anyone who can i would be extremely great full, thanks

earnest raven
#

what network tech do you have? DSL, fiber, cable..?

frozen sedge
#

cable

#

will be getting fibre in about two weeks

#

im thinking i might as well get a dream machine pro...

#

sorry for the late reply, if you do respond to me @ me im kind of inactive here XD

acoustic zephyr
#

Do you have an idea what could be the problem?

fast drum
acoustic zephyr
#

Sure

#
Server code:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
port = 12345
s.bind((ip, port))
print ("Socket binded to %s" %(port))
s.listen(5)   
print ("socket is listening")
while True:  
    c, addr = s.accept()
    print ('Got connection from', addr )

Client code:

import socket
s = socket.socket()
port = 12345
s.connect(('import socket
s = socket.socket()
port = 12345
s.connect(('192.168.1.47', port))', port))
#

I think it a firewall problem because when I run the codes on 2 cmd, it works but if I run it on 2 different pc, it never finds the other port.

exotic solar
#

All of the computers have to be on the same local network

acoustic zephyr
#

Yea ik that

#

We are on the same network

#

Both are passing through the same router

storm saffron
#

what actually is the blanked out part

#

no need to censor it if it's a local ip

acoustic zephyr
#

True

#

Here

#

I found the problem

#

It that Windows Security blocks the connection

#

Now how do I do so that it won't block my connection?

storm saffron
#

change your firewall settings

acoustic zephyr
#

Yea but when someone wants to use my progamme, they won't go and close their firewall in the settings

#

I want to be able without going in the settings

#

I want it to ask for access

#

Or I was wondering to try to create a path with 2 clients and one server going through the internet

storm saffron
#

it does automatically

#

windows will show that prompt if it hasn't been shown before

#

if it didn't show for you then you must have clicked 'no' for python.exe before

exotic solar
#

Aside from creating a common interface, did WSGI also fix the speed problem with older CGI-compatible servers?

A long time ago, servers invoked scripts for a dynamic response upon each request using standardized header names in the environment variables, should the script new access to them. (CGI is what standardized the header names). The problem with these servers is that they were slow, each time a script was called, the interpreter had to restart.

What I'm trying to figure out is if the systems of servers delegating requests to the Python web frameworks without having to restart the interpreter (the thing delegating the requests was already using python) was specified in WSGI, or if that was what already happening, and WSGI only standardized the interface between the two?

storm saffron
#

i wasn't aware that wsgi specified anything about how the framework works

exotic solar
#

What do you mean?

acoustic zephyr
gloomy root
# exotic solar Aside from creating a common interface, did WSGI also fix the speed problem with...

did WSGI also fix the speed problem with older CGI-compatible servers?
For python -> Not really, WSGI came around because there was a lack of a interface that allowed you to pick and mix frameworks and servers
which was pretty limiting because what ever framework you picked could only use it's supplied server without any room to be reused which made it hard for developers both maintaining and developing with the libraries

#

The idea of having a single web server and just processing it via the framework had been around before wsgi

#

WSGI just made a more pythonic interface for frameworks and servers to interact allowing you to say roll with Flask and UWSGI but then maybe switch out to Flask and Gunicorn without rewriting your entire program

errant bayBOT
#
Bad argument

Converting to "int" failed for parameter "pep_number".

#
**PEP 333 - Python Web Server Gateway Interface v1.0**
Status

Final

Created

07-Dec-2003

Type

Informational

gloomy root
#

Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few [1]. This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa.

By contrast, although Java has just as many web application frameworks available, Java's "servlet" API makes it possible for applications written with any Java web application framework to run in any web server that supports the servlet API.

The availability and widespread use of such an API in web servers for Python -- whether those servers are written in Python (e.g. Medusa), embed Python (e.g. mod_python), or invoke Python via a gateway protocol (e.g. CGI, FastCGI, etc.) -- would separate choice of framework from choice of web server, freeing users to choose a pairing that suits them, while freeing framework and server developers to focus on their preferred area of specialization.

exotic solar
#

@gloomy root thanks!

narrow minnow
#

I can't find this anywhere online but what happens to the server when it gets a request but never sends a response? Does it hurt server performance?

gloomy root
#

well that depends on a the server

#

it'll timeout eventually regardless as most clients implement a timeout as well as the server

narrow minnow
#

I see, is there a way to close the connection on the server but leave the client hanging?

gloomy root
#

no

#

when the connection closes the client will stop pending

narrow minnow
#

Ah. It's just that I've been thinking about a way to detect spam requests and make it seem like the server is down

#

But keeping all those connections open ins't good I see

storm saffron
#

well it depends on the server

#

at the packet level, if you just never send any packets back that's fine

#

but trying to implement that with a server like flask is impossible without tying up serving threads

#

so you're better off doing it in sockets

hoary sorrel
#

A tarpit is a service on a computer system (usually a server) that purposely delays incoming connections. The technique was developed as a defense against a computer worm, and the idea is that network abuses such as spamming or broad scanning are less effective, and therefore less attractive, if they take too long. The concept is analogous with ...

ember ledge
#

Hey, I'm having a small hiccup in trying to set up a git server with Apache. I have a test repo on my server, but attempting to clone it gives a 403 error. There is some documentation about how to do this, chiefly at https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP. The issue I'm having is, I think, a result of how my domain is set up. I decided not to set up my git server at <domain>/git, but instead at git.<domain>. I also host my personal website at this domain. This means that I have two directories named <domain> and git.<domain> in /var/www/html. I also have two .conf files, <domain>.conf and git.<domain>.conf in /etc/apache2/sites-available. The <domain>.conf file is pretty standard, as is the git.<domain>.conf file, with the exception of the inclusion of these lines:

SetEnv GIT_PROJECT_ROOT /var/www/html/git.<domain>
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias / /usr/lib/git-core/git-http-backend/

I suspect that the issue is in either the first SetEnv or the ScriptAlias, but I'm stumped. I have confirmed that the issue is not with file permissions, and changing the / in the ScriptAlias to anything else causes a simple repository does not exist error. I have also confirmed that the test repo is functional, as cloning it via SSH works completely fine.

<domain> is just a placeholder for the actual domain, as I have yet to implement any security, and don't want to reveal an insecure domain.

#

Pardon the essay but I’m dying.

storm saffron
#

rip

#

i think this probably isn't the best place for this question

ember ledge
#

I’ve tried every programming-related server that I’m in.

ember ledge
#

how would i connect to a raw connection type

hoary sorrel
#

what do you mean by "raw connection type"?

ember ledge
#

@hoary sorrel

hoary sorrel
#

OK - so that's just any sort of TCP socket at all. That just takes whatever characters you type and sends them directly to the remote without any translation, and prints out any characters sent by the remote without any translation

ember ledge
#

?

#

so thats just a normal tcp connection

#

@hoary sorrel

hoary sorrel
#

yep

ember ledge
#

would i connect to this using socket

#

and also how would i login and execute commands

#

@hoary sorrel

hoary sorrel
#

you'd need to implement your own server, with a login protocol that you devise, and a syntax for executing commands

#

Raw is the type of connection you'd use in PuTTY if you bind your own TCP server socket that's accepting connections. Whatever the user types into PuTTY would just be sent as data to that server.

ember ledge
#

hm

#

what if im making a api

hoary sorrel
#

That server can then do whatever it wants with what the user has typed in.

ember ledge
#

cause im making it into a api

storm saffron
#

apis generally operate over http

#

which tcp is not necessarily

#

tcp is just sending a packet of bytes

#

whereas http has method, url, all sorts of stuff

#

which generally makes it much more suitable for a relatively low speed api

ember ledge
#

hm

storm saffron
#

as in you wouldn't use http for a realtime FPS multiplayer protocol

#

but you could use it for chess

hoary sorrel
#

HTTP is a particular application layer protocol on top of TCP. You could build your own application layer protocol for your API, but that makes things harder for your clients, so you wouldn't want to without a good reason.

storm saffron
#

what's the purpose of the api

gloomy root
#

i mean hey

#

could always build a fast network gameplay with http/3 now

#

wouldnt be quite as fast as raw UDP sockets but its close

storm saffron
#

wait http/3 is a thing

gloomy root
#

yes

storm saffron
#

damn i'm so behind lol

#

i'm only just beginning to accept that http/2 is something i need to be aware of

gloomy root
#

http/2 but implemented in the UDP protocol

#

Its very new but has alot of potential with speed

#

Currently only supported by Chrome for browser

#

Firefox will probably get it when the h3 crate is production ready

raven gazelle
#

what ip should the client be connecting to and which ip should server bind to?
like public/private for each one
ping me if you end up answering

tall shore
#

i have to send 50 messages

ashen hearth
#

hey guys, i have a domain called electric.sh. is it possible to have a subdomain or something like get.electric.sh?

sonic oasis
#

whats this for?

ashen hearth
#

this is for my flask api

tropic condor
ember ledge
ember ledge
#

Np hope I helped.

warm kite
#

can someone help me with port forwarding

#

what should I fill in the 'External Source IP Address'?, my public IP, right?

clear bobcat
warm kite
clear bobcat
#

You can try in offtopic channels

warm kite
#

okay, sorry.

prisma cobalt
#

just let them ask @clear bobcat , this is hardly the most active channel and people are more likely to know how to answer here since its #networks

#

someone here helped me with MY portforwarding before

late moss
#

hey what are debian mirrors ?

wraith grove
#

Mirrors are copies of something

#

So they are links to copies of the Debian package repository

lunar veldt
#

does someone know how to sniff tcp packets with scapy?

ember ledge
drowsy slate
#

what ip address for a server allows it to be hosted on the router, not just on the host device?

drowsy slate
#

so if i use the ip 127.0.0.1 (which is the ip for localhost, which is scoped to just my device), what can i use so it is scoped to my router

hoary sorrel
#

You can use 0.0.0.0 to accept connections on any interface.

modern mason
#

How do I turn off any firewalls on my Python script?
Im doing some networking stuff, and I think my windows defender broke something

tepid merlin
vocal kernel
#

Hy all! My name is Marius Avram and i am CCNA certified trying to learn python for network automation. Glad to be here.

west mountain
#

I'm not sure what I'm doing wrong here, I'm not receiving any data. Probably missing something obvious here, could someone help point it out please?

#

Thanks in advance!

tall mesa
#

in s.recv(1024) you might need to decode the message try doing s.recv(1024).decode() . im not sure if im right because im still pretty new to this stuff.

west mountain
tall mesa
#

you welcome glad i could help!!

#

I actually have a problem with my script too. I am trying to make a simple messaging app thingy on the command line but i am not able to send one clients message to the other. I tried using multithreading but i have no clue what the bug is. Help would be greatly appreciated.

#

these are my scripts

errant bayBOT
#

Hey @tall mesa!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

wraith grove
#

@tall mesa Your client has to wait for you to input something before recieving anything from the server

tall mesa
#

ohhhhhhh

#

but then it cant send messages to the server

wraith grove
#

@tall mesa There are a few solutions to this. Threading or asyncio are both good options, where you can have the bit that deals with input not block the bit that deals with network communications

#

You could also figure out some way to do a timeout on the input, or use a GUI platform that does the threading for you behind the scenes

tall mesa
#

oh ok

#

thanks!

lunar veldt
#

Hey, does someone know how can I detect when someone connects to my Wi-Fi?

wraith grove
#

Check your router or AP's arp table

#

almost all routers have it prominently displayed in their web GUIs

#

If you are just trying to stop people from connecting to your wifi, you should set a strong password. MAC filtering also gives some protection, but can be defeated if anybody can get the mac address of anything on your network.

potent nymph
#

where should i start w/ networking?
please ping on reply

flat umbra
#

Yes please suggest the foundation required for networking

storm saffron
#

What do you actually want to learn

#

IT/infrastructure, low level protocols, security, hardware?

#

or specifically to python

flat umbra
#

Specifically to python

lunar veldt
#

before learning networking specifically to python you should literally learn networking

#

but if you want you can give a look to the scapy module, used for packets interception

tall mesa
#

i just started networking last week and i started with sockets and threading. is that a good place to start?

torn raven
#
    async def get_guildlist(self, data):
        listt = [self.bot.guilds]
        return listt

Why doesn't this work? The page is just loading and loading

potent nymph
#

hey

#

can someone tell me how to make a public chatroom(which can be accessed by people outside my router) .
i already know how to make a local chatroom but i cant find any video to make a public chatroom

torn raven
storm saffron
potent nymph
#

@storm saffron is there any other way to do it or is that the only way?

storm saffron
#

well the alternative is host it somewhere else

#

but at the end of the day you have to allow packets to get to the server

potent nymph
#

so can i host it heruko?

#

@storm saffron

storm saffron
#

yep

potent nymph
#

thank u

tall mesa
#

i am have a problem with sending my client messages

#

import socket
import threading

HEADER = 64
PORT = 5555#the port we want to setup our server in
SERVER = socket.gethostbyname(socket.gethostname())#gets the ipv4 adress of wifi
ADDR = (SERVER, PORT)
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = "!DISCONNECT"

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)

messages = []
def handle_client(conn, addr):#this will run for each client seperatly
print(f"[NEW CONNECTION] {addr} connected.")#prints adress of person who connected

username = conn.recv(2048).decode(FORMAT)

connected = True
while connected:
    msg_length = conn.recv(HEADER).decode(FORMAT)#how many bytes you can recive and also decodes the message
    if msg_length:
        msg_length = int(msg_length)#convert length of message into integer
        msg = conn.recv(msg_length).decode(FORMAT)
        if msg == DISCONNECT_MESSAGE:
            print(f'[{username}] has left')
            connected = False

        print(f"[{username}] {msg}")
        messg = f"[{username}] {msg}"
        messages.append(messg)
    
    if messages != []:
        conn.send('message recived'.encode(FORMAT))
        #messages.pop(messages.index(0))

    conn.close()

def start():
server.listen() #listening for new connections
print(f"[LISTENING] Server is listening on {SERVER}")#what ip adress its running on
while True:
conn, addr = server.accept() #stores connection and address when someone joins server
thread = threading.Thread(target=handle_client, args=(conn, addr))#passing the arguments for the handle client function
thread.start()
print(f'[ACTIVE CONNECTIONS] {threading.activeCount() - 1}')#prints how many people are connected to server

print('[STARTING] server is starting...')#output to say server is started
start()#calling the start function

#

in the "msg_length = conn.recv(HEADER).decode(FORMAT)"

#

it gives me this error

#

"bad file discriptor"

#

Thanks in advance!

prisma cobalt
#

Can your ISP a see what you search on google since is HTTPS
I mean when you search something the URL contains what you searched

ember ledge
#

yes of course,

silent rivet
#

If you use any sort of HTTP/S proxy, the proxy provider can likely see the contents of your URL. So unless you're using an HTTP/S proxy from your ISP, then not they should no be able to see the contents of your URL if you are using HTTPS.

prisma cobalt
#

So google searches really are anonymous?

#

@silent rivet

silent rivet
#

Well... that on the other hand is debatable lol

prisma cobalt
#

Lol, I don’t have web activity turned on so in theory it shouldn’t save where I go

#

iN tHeOrY

silent rivet
#

Google does tracking under the hood and I don't know much about what they share with third parties. I just know HTTPS connections are safe and encrypted as long as you don't use a proxy.

prisma cobalt
#

I mean google is a private company and doesn’t stand to gain from reporting users to let’s say the police. Third party advertising sites on the other hand...

silent rivet
#

There's a lot of assumptions to be made there.

prisma cobalt
#

Wdym?

silent rivet
#

I don't speak for Google, but typically a company is more interested in protecting itself than single one off users. I can't say for sure if they actively report users to the authorities, but they'd probably be cooperative during an investigation would they come asking

prisma cobalt
#

Google is “88%” cooperative with authority investigations and requests

#

I read somewhere

#

But unless the police have a reason to ask for your browsing activity then google doesn’t tell them explicitly

#

Altho some keywords are monster like searches about kiddie porn and drugs and guns (terrorist stuff)

slender steeple
#

@prisma cobalt ISP can see the domain of the site you're requesting via DNS

#

so it can see that you're on "google.com", but not what you're searching

#

(unless you have dns over https)

potent nymph
ember ledge
fallow tree
#

Hello Everyone anyone suggest a good resource on python for hackers.

light zealot
#

How do I connect two different computers?

prisma cobalt
light zealot
#

Pls guys help me out , i suck at networking

#

Also can I randomly choose any port in range 0 to 65535 (excluding those in 1000's)?

prisma cobalt
light zealot
#

Any link or code

#

Actually I'm new to networking

prisma cobalt
light zealot
#

thanks I'll check it out

#

Also one more question @prisma cobalt (Sorry if I'm disturbing you)
For connecting different computers the host should be equal to the IPV4 address of the server or something else?