#networks

1 messages · Page 9 of 1

coarse summit
#

or it was just your example

#

ill just check it out

edgy pelican
#

and its open source i may add

edgy pelican
open isle
#

Hi, this channel is about computer networks like the Internet, not for the social kind of networking. Also, we do not permit unapproved advertising. Please review our #rules. Thanks.

autumn glen
#

So I'm learning about sockets and python and I'm wondering if there's a better way of handling errors in the code, rather than writing a bunch of try except statements. Such the following example, to deal with connection reset errors:

while True:
  try:
      msg_len = conn.recv(BUFSIZE).decode(FORMAT)
  except ConnectionResetError:
      do_something
      break
  do_something_else
  
  try:
    sth_else
  except anerror:
    something
    break
edgy pelican
#

its a fact of life

gusty cargo
#

what up im new to python

edgy pelican
#

wat up

flint marten
#

so i have a TCP server-client application currently running. currently, the issue im currently having is that i need to change the script so that messages from the client will run linux commands like ls on the server.

#

Client:

serverName = 'servername'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print ('From Server:', modifiedSentence.decode())
clientSocket.close()```
#

Server:

serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('',serverPort))
serverSocket.listen(1)
print('The server is ready to receive')
while True:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024).decode()
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.
encode())
connectionSocket.close()```
#

i dont really know how to change much as my knowledge in python isnt good and the professor gave us the script for the server-client beforehand

coarse summit
#

it's a bad idea to let a client execute commands, especially when there's no auth

subtle steppe
#

If someone could help, I'd appreciate it^

final meteor
subtle steppe
subtle steppe
# final meteor Show the IPs u get

Server is on Mac and Client is on Linux.

Mac
~ > ipconfig getifaddr en0

10.180.187.246

Linux
:~$ ifconfig
enp0s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.211.55.7 netmask 255.255.255.0 broadcast 10.211.55.255

final meteor
subtle steppe
final meteor
#

Right. Never used it but might be worth to look into the network settings. If its using NAT that could be the reason. Change it to bridged or similar if such an option exists

subtle steppe
scenic flower
#

I can send message but can receive it

#

please holp

edgy pelican
#

so you can send messages and recieve them?

scenic flower
#

listend to broadcast does not work as intended

scenic flower
edgy pelican
#

oh

scenic flower
#

I need to know why isnt this working

edgy pelican
#

i see what you got wrong

#

but firstly

#

GO USE ASYNC

scenic flower
#

yeah i was goona ask about that too

errant bayBOT
#

:incoming_envelope: :ok_hand: applied timeout to @edgy pelican until <t:1701583374:f> (10 minutes) (reason: duplicates spam - sent 4 duplicate messages).

The <@&831776746206265384> have been alerted for review.

scenic flower
#

woah

#

what happened

#

i didnt do anything i swear

#

whats up with the bot

edgy pelican
#

oops

#

certified oops moment

edgy pelican
#

so

#

you could do it with threading

#

but its a huge hassle

#
clients = []

async def handle(client):
    try:
        while True:
            data = await client[0].recv(1024)
            print(data.decode("utf-8")
    except ConnectionResetError:
        print("ConnectionResetError occurred")

async def main():
    server = await asyncio.start_server(
        handle, '127.0.0.1', 3001)

    async with server:
        await server.serve_forever()
``` for the server part @scenic flower
#

wtf

#

<@&831776746206265384> sus

#

dude sent that the second i sent my msg

mental mantle
#

i fucked up my selfbot

#

oopsies

edgy pelican
#

!rule tos

errant bayBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

mental mantle
#

dont care

edgy pelican
#

absolute

hoary sorrel
#

!ban 897978458163003432 self-bot

errant bayBOT
#

:incoming_envelope: :ok_hand: applied ban to @mental mantle permanently.

edgy pelican
#

moment

scenic flower
#

Asking help for projects is not allowed ?

inland rampart
#

"this dude" only got muted for 10 minutes, as the message says, automatically by the bot for sending too many duplicate messages in a row. that's an antispam measure and if it triggers when it shouldn't a mod usually unmutes the victim.

scenic flower
inland rampart
#

There's no rule prohibiting asking for help, indeed.

scenic flower
#

For websites

scenic flower
#

I make website and mobile app

edgy pelican
#

certified oops moment

edgy pelican
#

@lapis lava

#

are you specializing in any particular field of CS?

scenic flower
edgy pelican
lapis lava
#

okk

#

i am here

edgy pelican
#

i cant talk much atm im busy

edgy pelican
lapis lava
#

now can you tell me

scenic flower
lapis lava
#

whare should I start to learn networking

#

and would it create any positive impact on my career

#

and also are there any scopes for the networking

edgy pelican
# scenic flower idk i though it was the right thing to do is it wrong ?
import asyncio

clients = []


async def handle(client):
    try:
        while True:
            data = await client[0].recv(1024)
            print(data.decode("utf-8")
    except ConnectionResetError:
        print("ConnectionResetError occurred")


async def main():
    server = await asyncio.start_server(
        handle, '127.0.0.1', 3001)

    async with server:
        await server.serve_forever()``` do this, and change your normal sockets code to use asynciop
edgy pelican
lapis lava
#

actually I am a first year student so don't know much

edgy pelican
lapis lava
#

I just want to upskill myself

edgy pelican
#

are you an undergrad student

lapis lava
edgy pelican
#

ah ok, do you want to specialize in anything or be a certain type of engineer?

lapis lava
#

i am actually doing btech in cse branch so just want to stick to my domain'

scenic flower
#

oops I made a silly mistake

lapis lava
#

computer science engineering

edgy pelican
#

i see

#

so you just want a general knowledge and overview?

lapis lava
#

i want it to be add in my skillls

#

should I start it

#

or it willl take me off the road

edgy pelican
#

i'd suggest you learn theory and stuff before

(but then again, im just a random highschooler online, take everything i say with a grain of salt)

lapis lava
#

what do you mean by theory atuff

edgy pelican
#

the infrastructure

lapis lava
#

okk

#

so I should start networking ??

edgy pelican
#

ig if you want to

lapis lava
#

okk

#

thanks for yor advice and time

#

i am very greatfull

scenic flower
#

why is this error occuring ? ```py

An unexpected error occurred: object bytes can't be used in 'await' expression

async def listenToBroadcastMessage(clients=CLIENTS):
try:
for client in clients:
receivedMessage = await client.recv(1024)
try:
receivedMessage = receivedMessage.decode('utf-8')
print(f"Message received: {receivedMessage}")
except UnicodeDecodeError:
print("Error decoding message: UnicodeDecodeError")
except ConnectionResetError:
print("ConnectionResetError occurred")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Handle or log the exception as needed ```

#

you cant receive bytes in an await function ? is that it ? is there a work around for this ?

edgy pelican
#

um

#

so

#

you're doing this wrong

edgy pelican
#

you create a new server that you serve_forever(), which specifies a handler for every new client

scenic flower
edgy pelican
#

is

#
    server = await asyncio.start_server(
        handle, '127.0.0.1', 3001)```
#

creates a server

#

using handle as the handler

#

so when someone sends a request

#

the server delegates the reader and writer to the handler

#
async def handle(client):
    try:
        while True:
            data = await client[0].recv(1024)
            print(data.decode("utf-8")
    except ConnectionResetError:
        print("ConnectionResetError occurred")```
scenic flower
#

i do it like this ```py

HOST : str = "127.0.0.1"
PORT : int = 3001
CLIENTS = []

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
server.bind((HOST, PORT))
server.listen(5)
print(f"Listening on server on host {HOST} on port {PORT}")

#

why isnt it allowing bytes what the reason for that ? @edgy pelican An unexpected error occurred: object bytes can't be used in 'await' expression

edgy pelican
#

try using what i did

#

oh

#

i see

#

@scenic flower the asyncio version uses its own socket library

#

asyncio doesnt use socket objects

edgy pelican
#

it uses its own sort

inland rampart
edgy pelican
edgy pelican
scenic flower
edgy pelican
#

relatable 😔

scenic flower
#

damn bro

scenic flower
edgy pelican
#

so

#

the normal socket library is "synchronous"

scenic flower
edgy pelican
scenic flower
#

you mean we cant write asynchronous stuff ?

edgy pelican
#

when you do thing.recv(...)

#

the whole program stops

#

its kind of fixed by threading

#

but

#

its janky at best

#

asyncio is a much better way to do this

#

because async things have a thing called an event loop

scenic flower
#

dam i wrote all this code down the drain

edgy pelican
#

basically what it does is its very smart and knows when your program isnt doing anything

#

so it can do another thing while its waiting on the other thing

scenic flower
#

I know threading

inland rampart
scenic flower
#

or games or cybersec tools ?

edgy pelican
#

you dont strictly need to, it'll only save you several hundred thousand million billion trillion quadrillion septillion hours of frustration and pain and suffering and agony

scenic flower
# edgy pelican yeah

ok thanks a lot man otherwise I would have never know what is the point of socket library if it cant handle asynchronous stuff I mean socket stuff is meant to be asynchronous right ?

edgy pelican
#

wellll

#

for simple applications maybe

scenic flower
#

this makes no sense

inland rampart
edgy pelican
inland rampart
#

(one can with some effort make a synchronous implementation asynchronous (e.g. with a lot of asyncio.to_thread) but the opposite direction is more annoying, since you'd have to spawn an event loop just to call an async function.)

scenic flower
#

just like me

inland rampart
#

porting an application to be async is always a lot of effort, really. "Just make it impossible to write non-async applications" isn't really a solution to that 😛

scenic flower
#

hey come on man help a brother out

scenic flower
#

please pong me

inland rampart
#

Asyncio is used in a lot of places. "Cybersecurity tools" doesn't really describe much, but you see it in all sorts of applications. Backend frameworks too, like fastapi. For games I believe it's less common because people prefer to use threading there (because you need low latency in your user-facing stuff, and in asyncio control is only given back to other tasks when the currently executing one yields it).

cosmic cloud
#

I am looking for a like-minded people who want to get started with the python with the real time project. If someone interesting learning python right from the beginning, please send me a message

scenic flower
#

like to together or are they seprate ?

#

i mean is one used alongside other

#

?

scenic flower
#

with asyncIO

cosmic cloud
#

Send me a message who is interested

#

I will make a channel

#

And will get started

scenic flower
#

hey can someone help me ?

scenic flower
#

what will be passed as sock in this coroutine loop.sock_sendto(sock, data, address)

#

?

#

what is sock ?

#

I am refering to docs but it is clearly not mentioned where to get this value from

steady horizon
#

I'm curious as to why they didn't opt to use nonblocking socket objects

steady horizon
# scenic flower ok thanks a lot man otherwise I would have never know what is the point of socke...

Sockets can be either blocking or nonblocking, meaning operations such as connecting, receiving and sending either pause the program until they finish or do some work and return some status and continue on with the program. One way to handle nonblocking sockets in Python is by using the selectors module to sort socket objects into three lists depending on their current status and approach them that way. I thought asyncio uses nonblocking socket objects (from the socket module) under the hood in its own way

scenic flower
#

just asking

steady horizon
scenic flower
steady horizon
#

(Web sockets is a protocol "upgrade" from HTTP)

scenic flower
#

i mean you make the backend with python and frontend with javascript

steady horizon
#

I think there's a more popular web socket package on PyPi

scenic flower
steady horizon
scenic flower
#

because it is for web stuff ?

steady horizon
steady horizon
#

Well, Discord maintains an event gateway so its clients receive updates in real time using web sockets

#

The clients choose to subscribe to any event they want to be notified about

#

so as to not waste bandwidth I guess

#

What are you looking for exactly

#

They only use web sockets because Discord clients are web applications

#

They might have opted to using a custom application-layer protocol overall rather than WSS (secure web sockets) otherwise

keen gyro
steady horizon
#

¯_(ツ)_/¯

#

Squeezing as much throughput as possible using the least bandwidth possible

#

Considering Discord clients are integrated into the web application, it makes no sense to do so as you will have to support new web standards as they come. My question is why they use web sockets over HTTP 2 or HTTP 3

#

After all you can upload files and whatnot

#

Crazy web stuff

zealous flint
#

It would be a pain for developers to write bots

#

WSS is already an established protocol and has many client libraries and tools out there

steady horizon
#

Httpx supports HTTP 2

#

And I don't know what WS control frames Discord's event gateway API uses

#

Well, and the event gateway API

#

to an HTTP 2 server

edgy pelican
vale raptor
errant bayBOT
#

Lib/asyncio/base_events.py lines 961 to 962

sock = socket.socket(family=family, type=type_, proto=proto)
sock.setblocking(False)```
raven locust
#

Hey anyone can give me free sources like PDF which Theme is network and security using python?

bronze nova
#

Any idea why I cant connect sockets which are on the same router, im using eduroam's internet (unis wifi), however my network code doesn't work on my laptop and computer, however it works if I run the client and server on my laptop, or just my computer

coarse summit
#

since when have they changed this to networks?

edgy pelican
coarse summit
#

I suggested it on community meta but didn't realise they changed it

edgy pelican
crimson socket
#

someone help

crystal current
grand kayak
prisma cobalt
#

a workaround to this might be to use a separate proxy server which both devices can connect too and communicate through

earnest current
#

hello i have a error i don't get it "C:\Python311/Lib/site-packages\pydantic_core_init_.py", line 6, in <module>
from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'

#

please help

edgy pelican
#

wrong chanel

edgy pelican
#

!ot pls not here

errant bayBOT
grizzled cloak
#

hello everyone,
I am a new user of esp32 using micropython and in this field in general, I am facing a problem with sending data from the esp32 to a server using http request, Idk if it the best solution to use http requests to send a file, I have heard abut ftp, but I have no idea about it, and Idk what are the best protocols to use in this situation, I will be thankful for any help or guidance from you, and thanks in advance.

woven ferry
#

guys you got some good resources to learn networking and maybe some to automate network activities, services etc

edgy pelican
#

no™️

learn by doing

crystal bison
#

what is ground in the context of networking

#

?

crystal bison
#

and im willing to throw hands on it

edgy pelican
#

why is DH1 required in X3DH?

crystal current
# crystal bison what is ground in the context of networking

Is this what you're asking about maybe? https://www.quora.com/How-do-you-ground-a-shielded-Ethernet-cable

"Xtal" is a masterpiece BTW 😉

Quora

Answer (1 of 9): How do you ground a shielded Ethernet cable?

Technically, there is no such thing as an “Ethernet cable”. There are many cables that can support Ethernet.

So, your question is unanswerable unless you tell us what type of cable you are using…

  • Thicknet - 10base5 - 9.5mm coaxia...
crystal bison
#

and it truly is

#

so is the rest of the album

#

listen to geogaddi and music has the right to children

#

if u havent alr

modest stirrup
#

Anyone knows of a short snippet or github repo that uses python for reverse proxying?
I want to connect to a couple of localhost webuis from remote connections without resorting to remote desktop solutions.

inland rampart
modest stirrup
blissful dawn
#

Hi guys,
I was rewriting my code, that uses pyodbc (with ms sql) to use that database remotly. Since i can't just add users to the database, i can only use it locally. I did succesfully translate my pyodbc code to send and recive SQL data using socket and pickle. But i get an error when pyodbc returns just one row:
TypeError: cannot create 'pyodbc.Row' instances
Any idea how i can solve it. I searched online, i was using pypyodbc before but pickle couldn't handle it well at all.
I did try converting it to a list using: resoult = list(cursor.fetchall()), and even tried using for loop to retranslate it to diffrent list but it still was giving me the same error.

toxic mural
blissful dawn
#

I will as soon as I get home. So in 7hrs from now

tender thorn
#

hello,
I use software to analyze the spectrum. Is there a way to make it run for 5 seconds and then stop for 5 seconds like a while loop while retaining the settings? Do you think it's possible to do this with a script? or do you have any other Idea please

blissful dawn
blissful dawn
# toxic mural can you send the full traceback?

Traceback (most recent call last):
File "C:\Users\Michal\Documents\Python\client-server\UI\main.py", line 475, in Renamer
self.OCRMatch.multipleOCR(self.sql,self,settings, './frames/')
File "C:\Users\Michal\Documents\Python\client-server\UI\OCR.py", line 234, in multipleOCR
renameTo = sql.selectSQL(query)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Michal\Documents\Python\client-server\UI\mainSQL.py", line 63, in selectSQL
respond = send({"query":msg, "QueryType": queryType})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Michal\Documents\Python\client-server\UI\mainSQL.py", line 35, in send
return(recive())
^^^^^^^^
File "C:\Users\Michal\Documents\Python\client-server\UI\mainSQL.py", line 43, in recive
unpiclked = pickle.loads(msg)
^^^^^^^^^^^^^^^^^
TypeError: cannot create 'pyodbc.Row' instances

hard gale
#

Hey friends I have built an ASGI python web framework if someone interested please check out here: https://pypi.org/project/aquilify/

toxic mural
#

you should turn the rows into regular tuples before pickling them

#

it should just work as something like

rows = [tuple(row) for row in cursor.fetchall]
tender thorn
#

@blissful dawn
thanks for your response. if I understood your message correctly, I need to write a shell script?

blissful dawn
tender thorn
#

@blissful dawn
yes that's true, sorry if you find my question a little strange, I'm a beginner in IT, that's why I asked. Thanks for your help, I'll try it tomorrow and let you know if it works.

blissful dawn
# toxic mural you should turn the rows into regular tuples before pickling them

yeh it doesn't really works. I found yesterday or so when was dealing with pyodbc error altogether that there were problems with pickiling resoult so they plugged that hole. I assume it wasn't really checked before release, and since databases are rarely translated over TCP using custom software written on python, there were not many cases like mine

#

but i managed to make it work :

       try:
           self.cursor.execute(query)
           self.rows = self.cursor.fetchall()
           

           if not self.rows:
               #print("No data found")
               return None
           else:
               print("QUERY:",query)
               print("Return lenght:",len(self.rows))
               if len(rows) == 1:
                   self.cursor.execute(query)
                   self.rows = self.cursor.fetchone()
               else:
                   return self.rows

               

       except odbc.Error as ex:
           print(f"Database error: {ex}")

So i just rerun query if it was just one resoult of it and gona fetch one, that seems to be working so far
posting for evryone intrested, tho i doubt that anyone gona use it 😛

#

Ye i know it is not pretty etc, im just a hobbyst, and if it works, it works

blissful dawn
# tender thorn <@265189820848930816> yes that's true, sorry if you find my question a little s...

One time stand:

from datetime import datetime, timedelta
from time import sleep


def Run():
    timeStop = datetime.now() #assign current time
    timeStop = timeStop + timedelta(seconds=5)#assign add 5seconds to it
    while timeStop > datetime.now(): #do some code as long as timeStop is bigger than current tiem
        print("some code here")
        sleep(0.5)#just for decoration, slowing down the printing
    sleep(5)#sleep 5 seconds 
    Run()#repeat


if __name__ == "__main__":
    Run()

blissful dawn
tender thorn
#

@blissful dawn
oh thank you very much for your help

gaunt citrus
#

I am trying to build a network client that hides secret messages in the data section of an ICMP Echo packet, as well as a network server that captures the Echo packets and decrypts/prints the secret messages.

My server/listener seems to receive and correctly print the message sent from the client on my windows local machine but it does function on my linux virtual machine and I am not sure why. additionally, I can't see any of my traffic when i filter for icmp on wireshark

below is my code of the client:

ember ledge
#

hey i am looking for help from an expert in web scraping

#

anyone who can help dm me i will give you 25 usd

toxic mural
#

just ask your question

toxic mural
wintry birch
#

i know kinda unrelated, but did anyone try pump.co to lower AWS costs? I'm wondering if it is literally free money or if there is a catch... like loss of some functionality? does anyone know?

polar oar
slow light
#

Hello folks, would anyone have some good resources on implementing a vpn server and client, can be using sockets or through a protocol like openvpn. Or some book parts that explain the concepts 🙂

errant bayBOT
crystal current
errant bayBOT
#

9. Do not offer or ask for paid work of any kind.

crystal current
#

Upwork and Fiverr exist for that

unique kayak
ember ledge
ember ledge
#

Hi i have a bunch of annotated images and i want to make a python ai model that trains with those images so that it can detect the image from a given picture
can someone show me a good course or where i can get started

ember ledge
#

neural network

fleet perch
#

Network is bash this

#

If do notice py_sun

#

How to Maserati your business

edgy pelican
# ember ledge neural network

please read the channel description

Discussion on network protocols, technologies, hardware with relation to Python

#

network, as in the internet

keen pulsar
#

Is it possible to use my own personal cookies from my own browsing (in this case firefox) with requests/httpx?

ember ledge
#

Why not

keen pulsar
#

how then? I used an extension to extract the cookie of the site I want

#

but how do I load into python?

ember ledge
crystal current
keen pulsar
#

I meant, how do I load the file, the cookies.txt into the environment at runtime

#

not how I use it with requests

ember ledge
#

explain better

#

just read text file?

keen pulsar
#

yeah

#

do I just f.read() it into a variable and use that variable in requests?

crystal current
crystal current
wise leaf
#

a

#

hi

pulsar berry
#

hi

wise leaf
#

hi

pulsar berry
#

hi

wise leaf
#

hi

pulsar berry
#

hi

errant bayBOT
#

:incoming_envelope: :ok_hand: applied timeout to @wise leaf until <t:1702981637:f> (10 minutes) (reason: duplicates spam - sent 4 duplicate messages).

The <@&831776746206265384> have been alerted for review.

#

:incoming_envelope: :ok_hand: applied timeout to @pulsar berry until <t:1702981640:f> (10 minutes) (reason: duplicates spam - sent 4 duplicate messages).

The <@&831776746206265384> have been alerted for review.

sweet breach
#

lol

polar oar
#

nvm solved the problem

vagrant quail
#

So I have a question

#

How come .com can be more cheaper than a country domain

crystal current
#

Why wouldn't it be? It's the default domain for commercial sites in the US, a large and high value market

crystal current
vagrant quail
#

I suppose getting a .com would be more worthwhile then

hasty quest
#

ICANN was a mistake

outer pagoda
#

i can ssh into a server with the credentials but when i try to use paramiko client.connect it is providing authentication failed

#

Any idea why?

#

It works for some servers but for some it doesnt

#

The credentials are same for multiple servers so some of the servers work and some dont. So the credentials shouldnt be invalid

velvet radish
#

Can I reserved a section of a home network? Like if I want to make IoT devices, can I have them pick an address from a specific range e.g xxx.xxx.x.700-xxx.xxx.x.749?

crystal current
#

Otherwise you can do one by one IP reservations where you assign each IP to each device manually

#

Maybe there are other options, but that's what I know of

velvet radish
#

Yeah it was just a random selection and I used x as a place holder since I’ve had both 192.168 and 192.68 local IPs. I’m wanting to make a plug and play home automation system and part of that would require auto set up of each module used. So when I plug up a 3rd device, it will select a free up address from the accepted range and update the local flask app for the user to use.

hasty quest
#

Address allocation is handled by DHCP. You can see what configuration options your router's DHCP server supports, or host your own.

velvet radish
hasty quest
velvet radish
#

I’m willing to learn. Like I said, I want to make something plug and play where the main device handles all the configuration and the user just remakes it/configure their specifications e.g. time base automation.

zealous flint
#

these days home networks have dhcp built in to the routers, however

edgy pelican
#

but most of the config can be done in router dhcp srevers

crystal current
velvet radish
#

I would need a main device that host the flask app anyway so that seems like a great place to set this up lol.

steep acorn
#

can someone help to set up a minecraft sever?

steep acorn
#

seems its because the ports are closed but I dont know what to do

opal jetty
#

F

steep acorn
#

?

opal jetty
#

ISP issue, just give up

steep acorn
#

why?

steep acorn
#

if is that is true

crystal current
steep acorn
#

maybe that part is done correctly but but the ports are closed

#

or firewall :/

crystal current
crystal current
# steep acorn or firewall :/

If you're on Windows you can check the firewall at that level. If you're on a home network, you would know if you have a firewall at that level because you would have had to set it up

steep acorn
#

im gonna check

steep acorn
#

this is what I did, disabled the windows defender firewall, not sure if this is enough

zealous flint
hasty quest
#

Your computer isn't connected to the internet. Your computer is connected to your router, and your router is connected to the internet.

#

When your computer sends traffic to the internet, the router can easily forward reply traffic back to your computer.

#

But if random traffic from the internet comes in that wasn't preceded by an outgoing conection from your computer, there's no way for it to know which internal computer that should go to.

#

Unless you configure it to tell it to do that.

#

This is what port forwarding is

#

It tells the router which internal computer to send incoming connections to.

#

If you think you've done the forwarding step correctly, then you might want to check if you're on CGNAT, which is just another layer of NAT at your ISP

#

If you are on CGNAT, you are screwed.

#

You can find out by logging into your router and looking for its external IP address

#

(googling "my public IP" will NOT work. That will just show you the internet address of the CGNAT router)

#

If your router's external IP address is in any of these subnets, you are screwed:
192.168.0.0 - 192.168.255.255
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
100.64.0.0 - 100.17.255.255

steel pivot
#

CloudFlare tunnels can help you access the resources even if you are behind CGNAT

sweet breach
#

how would you explain Network Stack?

crystal current
sweet breach
steep acorn
mild tusk
#

Hey, how do I encrypt my intial message? I have written a server that functions as cloud. The uploading and downloading of files works just fine. I have even added password authentification and fernet encryption for the file transfer. I made it so that the server can handle multiple clients at a time, so that I can access it with multiple decives at a time. To ensure that every client has a secure connection, the client sends with the password my fernet key which is to be used for the file transfer. Obviously when you intercept the intial "handshake" between the server and the client you'd be able to read the password assigned to the specific client as well as the session encryption key, making all my security useless...how can encrypt the initial handshake when the server doesnt know the key before hand

slow light
edgy pelican
#

TLS is a protocol that's used to negotiate encrypted connections between clients

#

Transport Layer Security (TLS) is a cryptographic protocol designed to provide communications security over a computer network. The protocol is widely used in applications such as email, instant messaging, and voice over IP, but its use in securing HTTPS remains the most publicly visible.
The TLS protocol aims primarily to provide security, incl...

#

python has an implementation called ssl

#

!d ssl

errant bayBOT
#
ssl

Source code: Lib/ssl.py

This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side. This module uses the OpenSSL library. It is available on all modern Unix systems, Windows, macOS, and probably additional platforms, as long as OpenSSL is installed on that platform.

Note

Some behavior may be platform dependent, since calls are made to the operating system socket APIs. The installed version of OpenSSL may also cause variations in behavior. For example, TLSv1.3 comes with OpenSSL version 1.1.1.

edgy pelican
#

@mild tusk what are you using to ccommunicate with your clients? ssl or http?

mild tusk
#

Neither. I'm using TCP. Im using fernet for my encryption but the moment I go online(therefore stop using my localhost) i get the errorpy Exception has occurred: InvalidToken exception: no description File "/Users/juliuskorbjuhn/Documents/Programmierung/Python/Projekte/projectFolder/networking/logic/clientSide.py", line 23, in _decryptData return self.cipher.decrypt(base64.b64decode(data)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/juliuskorbjuhn/Documents/Programmierung/Python/Projekte/projectFolder/networking/logic/clientSide.py", line 45, in _download dataChunck = self._decryptData(self._recieveHeader()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/juliuskorbjuhn/Documents/Programmierung/Python/Projekte/projectFolder/networking/logic/clientSide.py", line 65, in main self._download(filePath) File "/Users/juliuskorbjuhn/Documents/Programmierung/Python/Projekte/projectFolder/networking/client.py", line 5, in <module> client.main() cryptography.fernet.InvalidToken:

#

I checked everything. Implemented meassures to check if hashed key is the same and thereby verifiying key integritiy(and the key is transmitted correctly). So i really dont know what leads to this error https://paste.pythondiscord.com/KGYQ

crystal bison
#

Hey im looking to create a home network

#

has anyone faced any issues with the above router

#

?

#

oops wrong one

crystal current
crystal bison
#

anyways I'm pretty new to networks

#

should i just invest in a router for now? and look into other network devices once i gain more knowledge

crystal current
crystal bison
crystal current
crystal bison
#

so i'd take it more as a compliment

#

anyways for context I'm trying to cover >1000 sqt of living space with adequate high speed wifi network coverage

#

I want to be able to stream HD content on multiple devices anywhere within the 1000 sqft

crystal current
#

I would think any modern router is fine for that. A lot depends on walls, interference etc

charred delta
edgy pelican
tribal dome
#

i have some code which connects to a websocket, sends a ping, waits for a pong and calculates the time it took to receive a response, instead of regular "ping ip" thing, is there a way i can use that instead of regular pinging to find the VPS/hosting provider that i need?

slow light
crystal current
tribal dome
tribal dome
#

pinging or traceroute just isnt cutting it for me, i'm just burning money by testing each VPS individually, putting my code in, testing the websocket latency because as far as i know theres no other way to connect to a websocket and test its ping pong latency in bulk

slow light
tribal dome
slow light
# tribal dome i connect to the websocket, send connection init message, and then i send ping a...

Well ping operates at layer 3 of the osi model so that is why you can basically ping any site/ip since it is supported by default on most systems (except if disabled), websockets however operate at layer 7 so you need to run something that accepts a websocket connection, automating this process of installing/running is definitely possible but requires more effort and tool knowledge so what you're doing is probably the quicker way

tribal dome
slow light
tribal dome
slow light
#

Yeah sure

hollow gulch
#

hi guys i wanna make a game in pygame, but i need to know what protocol should i use for tha lan multiplayer ?

hollow gulch
#

Even if i wanna transmit images ?

#

Nah, alr thx

edgy pelican
hollow gulch
#

Ok thx

ember ledge
buoyant bolt
#

guys how do i enter into e.loadinternal through python ? using requests module if possible

ocean bay
#

what do you mean 'enter'?

trim arrow
#

how can i make an .py file to an app or does that not work

crystal current
south pilot
#

Is there any way to control whether a script will route through a vpn or not?

tribal dome
#

im looking for a networking expert who can find the best hosting provider with the lowest latency to a certain websocket protected by cloudflare

crystal current
edgy pelican
south pilot
#

surfshark lets you do split tunneling through their gui, but they dont have a CLI to use

chilly swallow
#

anyone familiar with self supervised learning here?

south pilot
#

Not literally about learning

crystal current
slow light
south pilot
#

I have both wireguard and openvpn

slow light
south pilot
slow light
south pilot
#

I actually usually run a system-wide vpn, and I'd want the script in question to be excluded from that, rather than use a specific tunnel or something

slow light
south pilot
slow light
edgy pelican
south pilot
edgy pelican
#

is it?

south pilot
#

Yeah the pedagogy link was funny

agile stream
#

Hello, I am getting a n interesting error:

BadHttpMessage: 400, message:
  Expected HTTP/:

    b'[]'
      ^
  File "aiohttp/client_reqrep.py", line 899, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "aiohttp/streams.py", line 616, in read
    await self._waiter
  File "aiohttp/client_proto.py", line 213, in data_received
    messages, upgraded, tail = self._parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data

when calling a 3rd party endpoint (HTTP GET) from a kubernetes pod. Surprisingly, the request works without trouble when running locally with hte same code. What are the suspects here then? OpenSSL versions?

I also tried a simple curl from the pod via shell and that works as expected.

proud sleet
#

Hey, can someone recommend a telnet library? The most popular one seems to become deprecated soon as newer python versions are comming out

proud sleet
#

Assume that telnet is a requirement

edgy pelican
#

go migrate to ssh

quartz frigate
#

This one was last updated in June

#

November

#

Looks like there’s a few that’re still getting updates

edgy pelican
#

but why

edgy pelican
quartz frigate
edgy pelican
quartz frigate
#

I should make that available over SSH

quartz frigate
#

Those routers would look at you like a crazy person if your brought SSH in there

quartz frigate
edgy pelican
quartz frigate
sleek lake
#

I finally did it after 13 hours of continuous coding

#

AAAA

#

Who's into blocking malicious packets?

#

Took me 13 hours to be able to create a tool that blocks botnets 😆

#

Uplink and firewall doe

edgy pelican
edgy pelican
woven bay
#

Who knows how to implement multiplayer (online)

edgy pelican
#

there are multiple ways

#

UDP, TCP, HTTP (if you're a lazy di-), and it really depends on your usecases

woven bay
#

TCP,

normal gazelle
#

@exotic condor

Hers an example

#

Kind of bad , but..

#

The server can create a client task (when a user joins), and the client can create a command task (on command use)

#

The reason I did this is because it allows for more complex behavior like server events and more. Since certain commands may require waiting on something, the command needs to be a task.

# V.1
@Commands.command("input-test", 3, show_usage=True, description='Enter a number for testing.')
async def input_test(client:Client):
    message = Message(sender="Server", message="Please enter a number below", main_type=MessageType.CHAT, sub_type=MessageSubType.COMMAND_RESPONSE)
    await send(client, message, to_channel=True)
    event = Event('user', client.id) # user, channel, and server events
    message_output = await event.request()
    await send(client, message_output) # Send to user
    
    try:
        message = Message(sender="Server", message=f"You have entered the number : {int(message_output.message)}", main_type=MessageType.CHAT, sub_type=MessageSubType.COMMAND_RESPONSE)
    except ValueError:
        message = Message(sender="Server", message=f"Must be ant int", main_type=MessageType.CHAT, sub_type=MessageSubType.COMMAND_RESPONSE)
    await send(client, message)
``` Weird syntax and boiler plate code rn, but this a a custom command someone *could* make.
#

Im going to sleep. no idea if this is good, or terrible design choice. Too late now I suppose, since I have like..1200 lines of this

exotic condor
normal gazelle
normal gazelle
#

The only issue I see is each user using a command. Which means 2 tasks per client. Not sure how performance impacting that is. Works with 100+ clients rn

hallow vine
lament veldt
#

im looking for "computer network" course, tutorial etc. for my school exam
it could be on udemy, i guess there are on sales today
any idea ?

crystal current
lament veldt
# crystal current Maybe look at Network+ study materials, especially books, but if you want free v...
crystal current
fiery kite
#

Does anyone know how to check if the client or server has dropped the connection in socketIO?

viral slate
#

Never really have worked with oauth and want to set up an app to login to user's facebook business account and get page access tokens. Any ideas of how it might work if anyone here has worked with the Facebook Graph API or sdk? also id most likely be using the facebook-sdk library

golden tartan
#

Anyone done the CCNA V2 final exam

#

On netacad

coarse summit
#

what do you need help with?

golden tartan
#

I’m just wanted to ask any tips for it

#

As I got it soon

tribal dome
#

how can i find the exact hosting provider of a websocket? i'm connecting to their websocket, my latency is 7ms but its still too high and someone has a better one, there are no docs for the site or anything else, im desperate for help at this point, i tried many different hosting providers and a lot of different locations
the websocket uses cloudflare, perhaps if someone can make/has a tool similar to pinging ip addresses from different datacenters, but for websockets that would be extremely helpful, ive been trying to figure this out for a month now
i have a rough idea of where the websocket server is, that's why i have 7ms, but i can't figure out a better location because i assume it must be using a non standard hosting provider

coarse summit
#

huh?

#

if 7ms is too high

#

i cant even think what youre doing

tribal dome
#

its too high because someone else found 1-4ms, but they wont tell me

ember ledge
#

rent a better server 💯

#

try other lang than py also

tribal dome
tribal dome
#

i need help finding the specific provider with the specific location

tribal dome
edgy pelican
coarse summit
#

7ms is decent

#

and it is not like you can optimize the server

#

or the cables until the target

edgy pelican
#

:p

edgy pelican
coarse summit
tribal dome
#

well guys 7 ms would be more than enough for me, however i am getting absolutely wrecked by other people with 2-4 ms, that's why i need this help

edgy pelican
#

have you thought of the idea

#

that they might be closer to their vpses

#

i get 1ms latency from my srver!!!!!! (its an rpi on my local netwokr)

tribal dome
#

did you read my message? i need someone to help me with the exact hosting provider that is less than 6-7ms

#

i've already tried vultr, digitalocean, azure, google cloud, aws, contabo and a few more

#

all locations, i assume it's somewhere in france but not standard like paris or marseille that mainstream hosting providers use

#

maybe someone has a traceroute script like they do with ipv4 for different datacenters, but for websocket use instead or any tool similar to this

coarse summit
#

how surprising

#

btw what do you need the server for @tribal dome?

tribal dome
#

game skins trading

honest wind
#

hey guys, does anyone have experience with setting up a connection via wpa with a new raspberrypi 4

crystal current
honest wind
#

I have not worked with networking at all and have just been learning the past couple of days. I am currently attempting to connect a raspberry pi 4 to my laptop headlessly via my router. I can ping the raspberry pi without any lost packets and verified port 22 is open and listening. I also includes a blank ssh file on the pi's SD card and a wpa_supplicant file with the correct network name and password. Using Windows PowerShell, i have tried ssh -1 [variety of usernames and passwords for the raspberrpi] but am receiving either 'connect to host * port 22: Connect refused' or 'protocol v.1 is no longer supported'. I have tried researching online the past couple of days to see what I am missing/where i am making a mistake, and either can't find a solution or don't understand the technicalities. Just trying a different avenue to seek help.

dapper dew
#

Hi there, I've been playing around with Wireguard for two reasons, having my own VPN for forwarding all public traffic, and for security. Someone has mentioned that a prerequisite to connecting to one of their VPS' requires connecting to the VPN first, which I would like to consider replicating.
However, I'd like some second opinions on if this is worth doing. Currently I just use SSH keys to SSH into my VPS.

crystal current
toxic mural
#

SSH with password-based authentication disabled, some anti brute-force mechanism on the host like fail2ban, and automated upgrades together are pretty strong

wintry musk
#

I suck at networking. I'm behind a vpn, there's some IoT devices I can see on the vpn network, they are supposed to answer to UDP request, but they don't (or I don't see it on wireshark). I think it's because those devices and my machine aren't not on the same sub network. Could anyone help me ?

crystal current
ember ledge
#

Hello guys im trying to learn requests library can you suggest me a channel or course?

wintry musk
#

Someone explained to me as I don't control the VPN and as the router on the other side is blocking/filtering queries, I can't do what I want through that VPN.

bright gazelle
#

!rule 5

errant bayBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

bright gazelle
#

If they're blocking the traffic it's likely on purpose, helping with that would be against the rules here

snow fable
#

what exactly is this rpc stuff?

hasty quest
#

Remote Procedure Call

snow fable
#

k ty

tribal dome
#

i connect to a graphql websocket, but when i send a mutation even with 6ms latency i am only given a response after 100-2000ms, which makes me late because someone else figured something faster out, if anyone has any ideas or non-standard practices that can be used to speed this up please let me know 😄

ember ledge
#

adn what messages

tribal dome
light wraith
#

I am trying to implement my own tls client with http/2 and a open connecting.

import socket
import ssl
from hpack import Decoder


host = 'www.example.com'
port = 443


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)


context = ssl.create_default_context()
context.set_alpn_protocols(["h2"])

wrapped_socket = context.wrap_socket(sock, server_hostname=host)

wrapped_socket.connect((host, port))

x()

...

def x():
    req_raw = build_raw_http_request(
        method="GET",
        url="https://example.com",
        headers=headers,
        query=params
    ) # returns raw http data
    print(req_raw) # ->GET https://example.com HTTP/2... 
    
    wrapped_socket.send(req_raw.encode())
    
    response = b""
    while True:
        part = wrapped_socket.recv(4096)
        response += part
        if len(part) < 4096:
            break

    """ response is like "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00d\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\x08\x00\x00\x00\x00\x00\x7f\xff\x00\x00" which I think is binary for the response payload, settings etc
    """

    decoded_headers = decoder.decode(response) #-> hpack.exceptions.HPACKDecodingError: Unable to decode HPACK integer representation from <memory at 0x0000020DF3D14E80>
    print(decoded_headers)

#

Am I understanding it wrong?

ember ledge
tribal dome
knotty geode
#

hey i am begginer on flask.... i follow tuttorial and i run into this error. basicly i have to import my db but its keep saying that module dont found.. can anyone help me and thank a lot

ember ledge
#

yo im quickly trying to make a flask website but for some reason, the website returns nothing when i access it

ember ledge
crystal current
urban depot
#

Hi guys, trying to create an upstairs network but there’s no Ethernet through the house…

My solution is to install a Wi-Fi extender as a “slave” in the top floor and feed that into my upstairs router via Ethernet, which then serves my server and other kit…. what extender would be best to use for this, in terms of Ethernet throughput? I get great Wi-Fi speeds, even to my old extender but the Ethernet port is very slow

ember ledge
#

use electric wires to get internet upstairs

urban depot
#

Also aren’t they incredibly slow?

ember ledge
#

thats exactly how it works

urban depot
#

I think even a coaxial converter would be faster? 2.5Gbps maybe?

ember ledge
#

if u have u can try that also

balmy pivot
#

i need help 😦 so basically i am making a school project
i have an Ip address endpoint when i put it on my browser i get correct ip address of mine but when i use the endpoint through my fastapi which is hosted on deta space i get incorrect ip how can i fix this issue?

balmy pivot
#

basically my project is when someone open my endpoint i get their ip address

#

iam using https://docs.abstractapi.com/ip-geolocation basically it gives a url and your api key and when i copy that and i put on my safari tab i get my correct ip address

Abstract API

Abstract's IP Geolocation API is a fast, lightweight, modern, and RESTful JSON API for determining the location and other details of IP addresses from over 190 countries.

#

but when i use the same api inside my fastapi which is being host on Deta space i get the wrong ip address

hasty quest
#

If your request is going through any kind of internet gateway then you'll see the address of the gateway.

#

The IP address that this server tells you is whatever address it needs to reply to to send you the response.

#

anyways if you're using deta, surely you can just your instance's public IP address from them directly.

#

That's much more straightforward and reliable than some third party

#

And if you want the extra data like country, postal etc. you can still use the API.

#

Just provide the IP address directly in the request. It's an optional parameter you can submit.

#

I suspect that there may be a public IP address that goes to your deta instance, but connections out don't come from that that IP address.

#

Can you give more information about exactly what you're doing and what about the IP address you're retrieving makes it "wrong"?

#

It'd be a lot easier to actually diagnose that way

hasty quest
balmy pivot
#

I guess yes

#

Because I am in Pakistan

#

And I get ip for somewhere in India

#

I am guessing it’s returing ip for their data center?

hasty quest
#

Yes

#

The code is running in their data center, so the request is coming from their data center

#

This is an easy fix.

#

All you need to do is access the client IP in your code running on deta

balmy pivot
#

Really? Easy fix? I spent last 7 hours working on it and after seeing I can’t access the real ip I felt like crying

#

I already went to that docs

#

It talks about cloud flare and I know nothing about it

#

😦

#

So sigh now I feel so demotivated and upset because I worked so hard

#

I even used the X-Real-Ip header

#

And X-forwarded header

#

But none returned the correct ip

#

I can not express how badly I need help with this

hasty quest
#

Ok, I think these docs actually might not even be relevant. If your instance isn't behind cloudflare then I don't think you need to do much special.

#

Can you get logs from deta, like if you print() some stuff out in Python can you retrieve that?

balmy pivot
#

Yeah I can

hasty quest
#

what framework are you using, fastapi? flask?

balmy pivot
#

Fastapi

hasty quest
#

are you using nginx or anything else on top of it?

balmy pivot
#

No nothing

#

Only deta space

hasty quest
balmy pivot
#

I’m already using the Request

#

: (

hasty quest
#

Great

balmy pivot
#

But I am not getting the clients actual IP address

#

; (

hasty quest
#

request.client.host isn't giving it to you?

balmy pivot
#

No it isn’t 😭

hasty quest
#

What is it giving you?

balmy pivot
#

Data centers ip

#

In another close by country

hasty quest
#

So there is a reverse proxy of some sort. Maybe they have cloudflare on all Deta endpoints

#

what's the datacenter IP?

balmy pivot
#
  1. Something something
hasty quest
#

that's not enough, I need the whole thing

#

Rest assured if I wanted to attack some random data center I wouldn't need you to tell me its IP to find it

#

I want to check if it's in cloudflare's published IP ranges

balmy pivot
#

Ok just a moment

#

Btw it’s 2:33 am at my place and I’m reopening my laptop just for you. Please help me solve this issue Katy or my whole 7-8 hours will go to waste

hasty quest
#

Also, just to see, add this to your function and tell me if the IP address you're looking for is anywhere in these headers

print(f"XFF: {request.headers.get('x-forwarded-for')}")
print(f"XRI: {request.headers.get('x-real-ip')}")
balmy pivot
#

this is my current code ^

hasty quest
#

Ok so you're already inspecing XRI and XFF

#

Anything useful in them?

balmy pivot
#

no :/

hasty quest
#

Are they empty, None?

#

Are there some IPs in them but not your home IP?

balmy pivot
#

and its all wrong

hasty quest
#

Hmm so there is no XFF, and there is XRI from Amazon EC2... wtf

balmy pivot
#

what can i do now? : (

hasty quest
balmy pivot
#

can you give the exact code you want me to test

hasty quest
#
 @app.get("/mo")
async def read_root2(request: Request):
    v = f"Host: {request.client.host}\r\nXFF: {request.headers.get('x-forwarded-for')}}\r\nXRI: {request.headers.get('x-real-ip')}\r\nCCI: {request.headers.get('cf-connecting-ip')}"
    

    return v```
balmy pivot
#

katy is it okay if i can write you in private and share outputs there? : /

hasty quest
#

sure

balmy pivot
#

i sent you the response

violet kite
#

i lerning the programe and use python lang

plucky bluff
#

If I use proxies, can I interact with the site and for example order things with my account?

toxic mural
#

in general, yes

karmic glen
#

hi peps!
I saw the following code on stackoverflow that is supposed to continuously check if the connexion is up and I'm wondering if that would inevitably lead to a stack overflow because if the connexion never breaks the function will never return?

import requests,time

    def check():
        try:
            requests.get('https://www.google.com/').status_code
            print('online')
            time.sleep(5)
            check_again()
        except:
            print('offline')
            time.sleep(5)
            
    def check_again():
        try:
            requests.get('https://www.google.com/').status_code
            print('online')
            time.sleep(5)
            check()
        except:
            print('offline')
            time.sleep(5)
            check()
    check()
crystal current
ocean bay
#

you can write a cron job that schedules check() every 5 minutes

jagged sinew
#

Hello guys i am trying to connect to my socketio server from python. But there is a problem. The problem is my server need accesstoken to connect but on python when i try to connect without accesstoken it still says it connected but i still cant receive any data. can anybody help me with this?

`import socketio
import time
global accessToken
import requests
import json

server_url = "ws://localhost:2099/api/admin/face-search/consume?companyId=1"

accessToken="xxxxxxxx"
sio = socketio.Client()

@sio.event
def connect():
global accessToken
print("Connected")

@sio.event
def disconnect():
print("Disconnected.")

@sio.on('face_search_request')
def on_message(data):
print(data)

sio.connect(server_url, headers={'x-access-token': accessToken})

sio.wait()`

ember ledge
#

just use while loop

#

or smth

clever geode
#

is anyone able to help me with assigning an IP to a pico W server?

#

got locked due to timeout but the code is there

proud bone
#

hello guys. iam learning networking but i dont know if it is the time to learn python with it or till i finish networking ??,i need advice ?

rugged rose
#

how do I handle sending receiving data on a single separate thread ? (main thread gui, second thread networking)

crystal current
crystal current
# rugged rose how do I handle sending receiving data on a single separate thread ? (main threa...

I don't personally have experience with that but I would think any basic tutorial on threading should get you there. https://realpython.com/intro-to-python-threading/

In this intermediate-level tutorial, you'll learn how to use threading in your Python programs. You'll see how to create threads, how to coordinate and synchronize them, and how to handle common problems that arise in threading.

rugged rose
proud swift
prisma cobalt
karmic glen
# crystal current Lol, there are multiple problems here but that's not one that I see I wouldn't ...
import requests,time

def check():
    try:
        requests.get('https://www.google.com/').status_code
        print('online')
        time.sleep(5)
        check()

    except:
        print('offline')
        time.sleep(5)

check()

about the unecessary duplicate, I guess this works just the same doesn't it?

how come that doesn't fatally lead to a stack overflow after X amount of time if except: never gets triggered?

what type of error should also be specified and what could happen if none is specified?

sorry for asking so much questions I'm so curious 😁

crystal current
#

Or look through the documented errors request can throw and decide which ones you want to catch

edgy pelican
livid hawk
#

Hi, is this a good channel for questions about gRPC? Mostly general questions, for example:

I'm working on a project which already uses grpc for communicating between multiple running python processes. This means that every time we add a message type, we need to add a new service for that message to the proto file, and write a client class and a service class.

It ends up being fairly spammy, with lots of boilerplate code. I'm wondering if there's a better way to do this (other than, of course, "stop using gRPC for that", which if I had my druthers...).

normal oyster
#

I am having a little trouble with raw sockets
I did s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.hton(0x0800))
but that last argument always drops OSError: [WinError 10022] An invalid argument was supplied
I tried replacing it with socket.getprotobyname("tcp") and socket.IPPROTO_TCP, but still the same error...
Anyone knows why?

#

I am basically just writing the bytes manually
like ```py
buf = b""
buf += b"\x01\x02\x03\x04"

...

I am writing ip headers and tcp headers manually
edgy pelican
#

send whole code

#

@normal oyster

obtuse nacelle
tropic dagger
#

I found that the something always appends 8 bytes in the beggining of the packet.

bytearray(b'        {"a": 54, "r": 54}                                                                                                      ')
b'        {"msg": "HelloAck", "type": "str", "version": '

1st packet is the header data which is always 128 bytes maximum however in this case an extra 8 bytes got appended in the beginning. The message is still accepted since the json is still parsable*

the 2nd packet now becomes broken as the client expects 54 bytes incoming but 63 bytes was sent in total.

I tried running it on a different server but it would just be fine.

bytearray(b' {"a": 54, "r": 54}'                                                                                         ')
b'{"msg": "HelloAck", "type": "str", "version": "0.1.0"}'

Which is an expected response

I am not sure what is the specific cause of this but these are ran on a VPS under NAT so not sure if it helps.
If anyone knows please enlighten me.

tribal dome
#

is there a faster way to interact with a graphql endpoint other than websockets
i connect to a graphql websocket, but when i send a mutation even with 6ms latency i am only given a response after 100-2000ms, which makes me late because someone else figured something faster out, if anyone has any ideas or non-standard practices that can be used to speed this up please let me know 😄

ember ledge
#

hello

#

which network proxy lib do u suggest to use

#

i want to make port forwarding proxy

hearty field
wispy epoch
#

Hi, I'm having some trouble after enforce CSRF in a Flask Application. I use a decorator that check either if there is a Bearer token or CSRF token, this works fine, however when I try to do a POST call using postman for example I get 400 complaining about missing CSRF token

sour flint
#

i was wondering if anybody had any idea on how to do this:
theres a website called brainly with essentially all the answers to this stupid course im taking for school (health)
it gets annoying having to manually look up the questionson brainly clearing cookies etc
i was wondering if it would be possible to make some sort of script or maybe something where i would input the question, it would find the top question ( brainly is where people ask questions and others answer) and then it would display the top answer to the question
i have experience with development but not a lot of networking, i dont know if this is possible but it seems like it is

#

if i finish all the health assignments i get to do other coding stuff for robotics which i actually enjoy

#

but first i have to finish health unit

#

feel free to ping

errant bayBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

sour flint
#

or moreso how it breaks the rules

robust gale
ember ledge
#

using selenium gives low bot score than using http requests module yes?

gentle trench
#

Guys I am confused about public key cryptography.

Public key is used for encrypting messages. But I am unsure about the private key.
Some articles claim that private key is also used for encryption, whereas others say its only used for signing the hash of a message which is the appended to the original message to verify that the message has not been tampered with.

So if its only used for signing, then whats the point if the data is still visible to 3rd party? I have heard that in tls, it uses the public key to decide on a session key for symmetric encryption, but I am not sure how that works.

hasty quest
#

And the point of signing is the signature

#

You don't sign a contract to keep the contract a secret. You sign it to prove that you authorized it.

#

The point of signing is in fact that the data is not secret.

#

This is how website certificates work

#

When you connect to google.com, their server sends you a document containing a public key.

#

This document is signed by a certificate authority

#

Using the cert authority keys which are already installed on your computer, your browser can validate the signature of Google's certificate in order to determine that it is legitimately from Google

#

And then your browser can use Google's public key to validate data signed by Google.

edgy pelican
#

asymmetric encryption (in tls) is mostly used for 2 things
1: getting a symmetric key
2: ensuring authenticity

so, what it does is that both sides send a public key that is used to derive a shared symmetric key (key exchange)
the public key needs to be signed by a signing algorithm to ensure that it is sent by the first party (signature)

#

@hasty quest gave a more in-depth explanation

gentle trench
#

I am trying to create an application using sockets (that uses self signed certificate generated on the server side). The certificate should be stored in a pfx file with the private key, and then a cert file will be distributed along with the client application.

hasty quest
#

The key exchange happens when you receive the certificate from the server

gentle trench
#

the client send the key to the server?

#

or something like that, during a tls handshake

hasty quest
gentle trench
#

alright

#

Also I am confused about this. I have heard there are two types of certificates. Server side one and one for the client side.

Should the Server authenticate to the client, or the client authenticate to the server?

edgy pelican
#

public keys and signed data isnt secret

edgy pelican
gentle trench
#

oh that makes things clear

gentle trench
edgy pelican
#

i mean

#

the only time in which a client needs to authenticate itself to the server

#

is when the server wants to ensure that the client is a certain person

gentle trench
#

Oh

edgy pelican
#

which can already be done through passwords

gentle trench
#

Alright

edgy pelican
#

or logins

gentle trench
#

The same certificate can be used for tls and other encryption? Or is it that tls has a particular certificate

edgy pelican
#

i mean you could be able to use it for other things

gentle trench
#

oh

edgy pelican
#

but like

gentle trench
edgy pelican
#

why

gentle trench
#

As far as I know, .cer file does not contain private key

edgy pelican
#

maybe?

gentle trench
#

okok

#

thanks

oblique cloud
#

Guys anyone here with a deep understanding of web scraping?

#

I am trying to retrieve a script through a httpx response.

#

my code -> send code to server through a POST -> server sends code to engine -> engine runs -> engine returns result to server -> server returns result to me

I want to scrape the engine code through the response.

errant bayBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

oblique cloud
#

Before you flag and accuse, read the question first.

patent wraith
#

Has anyone had issues with FastAPI/Gunicorn servers refusing connections?

I was running a service handling ~3 QPS (on a single 4 core box) behind a network load balancer on aws from 3 clients I control in the same region (different AZs) and I've run into timeouts / ServerDisconnected exceptions when connecting to it on the client. Also seeing Target_RST_Count and NLB_RST_Count in my cloudwatch logs fron the NLB.

I think going from a single Uvicorn server to a Gunicorn server with 4 workers has improved the situation (only 2 failures overnight vs like typically 200 before), but I am honestly somewhat surprised I am getting any dropped connections for traffic inside AWS.

I think I'm probably going to make the service API idempotent (it is stateful) and add retries, but I feel like this shouldn't be happening? But maybe I have unreasonable expectations, I have not previously been responsible for this sort of thing.

Anyway, curious if anyone has similar experiences.

severe portal
fathom walrus
#

10.244.0.0/24 dev kube-bridge proto kernel scope link src 10.244.0.1
so the above route has no gateway specified. so all it does is specify what interface to use and what source to log for the next package hop directly to the destination, correct?

zealous flint
modest echo
#

anyone knows what this might mean

websocket: bad handshake: HTTP 404

in a VPNs log ? uhm im not good at this but i think im using a VPS to try to connect to a certain website that i put in the config so that means it cant reach it i guess?

heady bane
#

What do you consider small, medium, large, and enterprise networks based on the number of devices served?

crystal current
trim arrow
#

hey , How can i make an easy HTTPS request?

shy pebble
hearty field
patent wraith
modest echo
fathom walrus
#

Access points are the only sort of thing that bridge wifi connections to ethernet/wired connections, correct? There are no other such things in charge of turning wifi connections into ethernet of vice-versa, correct?

zealous flint
urban depot
#

Hi, anyone good at networking? My laptop can't seem to access any DNS records from my DC running on an ESXI server... DNS seems to be working as all other VMs can use DNS fine, I have tried flushing DNS etc and yes I have set my DNS server lol

#

It works fine when I SSH into ESXI from a console but doesn't work from my machine?

crystal current
urban depot
#

I can ping all VMs on the ESXI

tepid lance
#

anyone good in virtualbox ?

umbral hamlet
#

Hi, i'm pretty new working with sockets in Python. I'm implementing an example of file uploading from a client to a server, but it doesn't work. The algorithm i'm following is the following: The client reads 4096 bytes of a file opened in 'rb' mode, then it encrypts the data readed and sends the data to the server. If the EOF is reached (I checked the EOF as if there's no more data in the variable that holds the data), the reading loop breaks.

The code for upload a file is:

def upload_resource(file_path: str) -> None:
    try:
        with open(file_path, 'rb') as file:
            while True:
                byte_data = file.read(4096)
                print(byte_data)

                if not byte_data:
                    encrypted_end_tag = encrypt(key, b"<END>")
                    client.sendall(encrypted_end_tag)
                    break

                encrypted_byte_data = encrypt(key, byte_data)
                print(encrypted_byte_data)
                client.sendall(encrypted_byte_data)
    except FileNotFoundError as e:
        raise_error("Error when opening the file", e)
    except Exception as e:
        raise_error("Error when sending the file", e)
#

On the other hand, the algorithm I followed to receive and write the file uploaded is the following: Using a context manager, the script opens a file in 'wb' mode. With an infinite loop, the script receives a chunk of 4096 bytes, decrypts the data received and appends it to a variable called byte_file, that holds the received data. Is the end tag (b"<END>") is reached, the infinite loop breaks and the data held in byte_file is write into the file opened before.

The code of the server is:

def receive_resource(file_path: str) -> None:
    file_name = pathlib.Path(file_path).name
    download_directory = pathlib.Path('./downloaded_files/')

    if not download_directory.exists:
        os.mkdir(download_directory)

    saving_path = pathlib.Path(str(download_directory) + file_name)

    with open(saving_path, 'wb') as file:
        byte_file = b""
        
        while True:
            encrypted_byte_data = target.recv(4069)
            byte_data = decrypt(key, encrypted_byte_data)

            if byte_data == b"<END>":
                break
                    
            byte_file += byte_data
        
        file.write(byte_file)

The thing is that every time I run both scripts, basically the program gets stuck and there's no data wrote in the file. What I'm doing wrong?

#

If it matters, the decrypt and encrypt functions are:

def decrypt(key: bytes, data: bytes) -> bytes:
    """
    Given a key and a data stream, this function decrypts the data inside the data stream.

    Parameters:
    - key (bytes): A byte-like object that contains the key encoded.
    - data (bytes): The data to decrypt.

    Returns:
    - bytes: The data decrypted.
    """

    nonce = data[:AES.block_size]
    tag = data[AES.block_size:AES.block_size * 2]
    cipher_data = data[AES.block_size * 2:]

    cipher = AES.new(key, AES.MODE_EAX, nonce)

    return cipher.decrypt_and_verify(cipher_data, tag)


def encrypt(key: bytes, data: bytes) -> bytes:
    """
    Given a key and data stream, this function encrypts the data stream and sets the
    given key as the unlock key.

    Parameters:
    - key (bytes): A byte-like object that contains the key encoded.
    - data (bytes): The data to encrypt.

    Returns:
    - bytes: The data encrypted.
    """

    cipher = AES.new(key, AES.MODE_EAX)

    encrypted_data, tag = cipher.encrypt_and_digest(data)

    return cipher.nonce + tag + encrypted_data

Thanks! <3.

potent rose
#

Hi guys I’m working on a project to have python assign an external USB connected device a static IP address. I’ve done some digging on stack overflow and haven’t found anything useful. Does anyone have any ideas or experience with this?

crystal current
hasty quest
grizzled harbor
#

hi, im looking to decrypt my own network traffic through a pure python proxy
ive managed to get the proxy working, but right now it just blindly sends encrypted data between client and server
how can i use ssl to decrypt?

hasty quest
grizzled harbor
hasty quest
#

is this HTTPS?

grizzled harbor
#

yep

hasty quest
#

Are you using a web framework?

grizzled harbor
#

nope, everything is in that one file

#

i know its not ideal since resources like mitmproxy exist, but its been such a hassle to get it working that i opted to do it from scratch

hasty quest
#

Basically you need to generate a certificate and a key

#

You need to load both of these into the server

#

You also need to load the certificate into the client, and tell it to accept this certificate

#

How to do that depends on what the client is.

grizzled harbor
#

yeah i did make my own certificate, but i never figured out how to get the client and server to trust it

grizzled harbor
hasty quest
#

well if you are hosting it locally then of course you will reach it by localhost

#

It's not NOT a proxy because it's local

#

It's a proxy regardless of whether it's on localhost.

grizzled harbor
#

oh, guess im missing something then

hasty quest
#

What makes it a proxy is that it's between the client application and the server

#

If you want an internet URL that's another matter

grizzled harbor
#

well the more you know

hasty quest
#

And you can get one. You just need to buy a domain, and to have somewhere to host your code

grizzled harbor
#

dw im hosting it locally, i dont need it running 24/7

#

my other question is, how would i read my traffic while still letting it continue to its destination

hasty quest
#

Step by step:

#

client connects to you. You send back your cert. Client accepts it.

#

Client says "I want to GET / from google.com"

#

You say "I want to GET / from you"

#

You give the page to the client

#

This is called a forward proxy

grizzled harbor
#

yeah im following

hasty quest
#

The proxy can see all data exchanged between the client and the remote, which seems to be what you're after, right?

grizzled harbor
#

yeah basically
the full URL of the websites i access get encrypted in the CONNECT tunnel and i had no idea how to retrieve it

hasty quest
#

While you don't need a full framework you should at minimum be using an HTTP library

#

Correctly implementing HTTP from scratch is hard

#

But yes, the URL to be accessed is encoded in the request and you can retrieve it

grizzled harbor
grizzled harbor
hasty quest
#

That's already part of the step by step process I described above

#

With no HTTP you'd just skip the steps about certs

grizzled harbor
#

oh ok got it

grizzled harbor
cloud spruce
grizzled harbor
cloud spruce
# grizzled harbor ok so the client would connect after i make a new socket that connects to the sp...

no, the client connects with a tcp socket to the configured proxy and send the connect request (which doesn't contain much other then hostname, port number and possible proxy auth credentials) to the proxy in clear text (no encryption what so ever)
the proxy then resolves the hostname to an ip address and connects a tcp connection to that ip address and port that the client requested
as soon as the proxy connects to the server it will just start to pass the raw content byte stream (the tcp payload) back and forth between the client and the server

hasty quest
#

You'd have a listening socket

#

A listening socket waits for connections to come in and accepts them

#

Then it receives one or more requests over that socket

#

Again this is something you should use a library for.

#

Don't deal with sockets yourself, as implementing HTTP using only sockets is very complicated

grizzled harbor
#

any libraries you guys recommend then?

cloud spruce
#

yes, use libraries for as much as possible or this project will otherwise take a very long time and running the risk of never being finished

#

i would go for a asyncio compatible network library for the proxy to make life easier and the software more performant and scalable

#

and for just proxing you probably don't need to much http parsing or generating, you should mostly be able to pass the unencrypted traffic back and forth between the client and server

#

if you are going to watch the network traffic in the proxy you would need to have a CA or intermediate CA certificate on the proxy server that you can issue server certificates to the client with dynamically where you would more or less clone much of the information in the server certificate that you receive from the server and present your own to the client

#

the client mush have the CA certificate installed as a trusted root certificate for this to work, but that shouldn't be much of a problem as it's your own clients where you can (often) easily install the root CA on them (unless it's a Apple IOS device, then it's much more involved)

#

even with libraries this isn't a small and easy project if you want to inspect the traffic inside the encryption

#

you should probably have a cache with all the certificates that you "cloned" and issued to be able to reuse them as long as you get the same certificate from the server that you connect to, as generating certificate requests and signing them is a computationally heavy process that you don't want to do unnecessarily

#

you will have to learn quite a bit about TLS (what people usually call SSL, but is really the name of it's older ancestor) and certificates just to get this working properly

#

i think you will have to use a thread pool (or maybe even a process pool if the TLS library isn't implemented in external code that frees the GIL enough of the time) as well for much of the certificate stuff as that would otherwise freeze the asyncio code while running those computational heavy workloads

grizzled harbor
#

this is quite a lot to take in

cloud spruce
#

yeah, i staid it's not a small easy project, encryption is often quite involved

#

with the right libraries you will get a lot of the work done for you, but you will still have to stitch quite a lot together by yourself to get it to do exactly what you want it to do (as it's very much non-standard behavior that you are after)

grizzled harbor
#

would something like aiohttp work?

cloud spruce
#

maybe, but you're not really after standard http behavior, i think you would be better served by a TLS/SSL client/server python library (preferably not implemented in pure python, but rather C, C++ or Rust so that the code can free the GIL as much as possible while it's running the cryptographic parts of the code)

grizzled harbor
#
cloud spruce
#

interesting that it can also be used as a forward proxy, that sounds like one would be able to implement a request router or a basic load balancer with that

grizzled harbor
#

sweet, now to actually get it working

acoustic storm
#

Hey guys I was following a web scraping tutorial and the instance i opened the Program the next day my entire router got banned from that site

#

What can be the issue?

#

And how to access the site?

gloomy root
#

You probably spammed the site with requests and now your IP has been banned

acoustic storm
#

I was checking online proxies

#

Like the proxy rotation tool

hearty field
#

If you didn't have permission - You should just take the L

acoustic storm
#

Whats the point of web scraping then?

#

I think i accessed the api with an expired cookie

hasty quest
#

You did something that pissed the service operator off

coarse summit
acoustic storm
#

I used an expired cookie

coarse summit
#

only a bot would use an expired cookie

acoustic storm
glass ibex
#

wow guys i love networks

trim arrow
#

hey

#

an questing

#

How can i make an app like Messages when more users are in and someone writes something in a chat that the message comes to all users?

#

🤔

#

pls send me the answer to dm TY

wispy spruce
#

Im having trouble getting information from a post request. I want to access the data under the 'Response' tab in Inspect element because it is the only piece of data that differs between successful/failed logins.
Ive tried looking through all of the response data, html content, and even BS data but its always the same (excluding timeframes) with no signs of successful login.
The only work-around ive found is using Selenium but its far to slow and I need it to be fast.
(ps- the status code is always 200, ive tried that too)

def postSkyward(user, password):
    payload = {'codeValue': user, 'login': user, 'password': password}
    response = requests.get(url=skyward, data=payload)
    soup = BeautifulSoup(response.text, 'html.parser')

    htmlContent= response.content.decode('utf-8')  # Decode the bytes to a string
    return [soup, htmlContent, response] # soup, html_content, and response is ALWAYS identicle, despite the password changes
ember ledge
#

Hello guys, I'm currently doing a Google System Administration and IT Infrastructure Service course from Coursera, however I think I'm unable to retain most topics and therefore I'd appreciate it if someone could recommend a book related to those topics. (DNS, DCHP, Proxies, FTP etc.)

bright zealot
#

join

wispy spruce
#

he posted a scam link to some server that got autodeleted by the bot

brazen ferry
ember ledge
brazen ferry
#

Computer Networks by Tanenbaum was the university textbook in my time, but maybe you are after something more specific than that?

ember ledge
#

I'm still willing to look into it, as long as it makes me learn something, I don't have much knowledge of this so it might be helpful regardless
Appreciate it

misty orbit
#

any doc or video on how to setup https with fastapi?

ripe grove
#

Idk if this is the right channel but uhhhh

Going into more specifics of APIs . . . . What the heck is it and how do i use it. And why does every site have it so different and weird.

I can get an API key and stuff from a sit but than what do i do with that? I don't even know how to get any info from it yet

Or alternatively can you have a script visit a website and just grab the data it needs? Im just trying to automate doing that by hand, i just go into inspect element and copy paste part of it to a peice of code whenever i wanna update it

hearty field
#

Most of the sites will have an API documentation -- You will have to know basic-level python or of course other languages

I would recommend looking for config's or tutorials how to setup your API and try to retain that information

#

Usually the API Key gets stored in a script and will be used to send/receive queries in functions

azure grove
#

Is it possible to make automatic instagram note changer, so it changes like every 10seconds to other note?

indigo vault
#

Hey everyone, here is a video I made (or at least to the best of my abilities lol) about how to programatily using python library scapy you can power up remote hosts. Hope this can help someone! https://www.youtube.com/watch?v=MOYJkq4RfPQ

Ever wished you could wake up your computer from afar, just like magic? In this video, I'll show you how to harness the power of Wake-on-LAN (WoL) using Python to remotely power up your computer! Whether you're miles away or just cozying up in bed, this handy trick will make your tech life infinitely easier.

We'll dive into the basics of WoL, e...

▶ Play video
weary tapir
#

Hi, I'm trying to figure out my ipv4 address, i used this snippet of code but it's giving me my default gateway instead. Does anyone know how i could get my ipv4 address instead?

def get_ip():
    hostname = socket.gethostname()
    ip_address = socket.gethostbyname(hostname)
    return ip_address
cloud spruce
# weary tapir Hi, I'm trying to figure out my ipv4 address, i used this snippet of code but it...

that does give you one of your own ip addresses, not the default gateways ip address
but it will only give you one ip, more or less at random, which might not be the right one if you have more than one ip address on your system
instead, this will give you a list of all of your ip addresses (both IPv4 and IPv6):

import socket

ip_addresses = [ip[4][0] for ip in socket.getaddrinfo(socket.gethostname(), None)]
cloud spruce
# misty orbit any doc or video on how to setup https with fastapi?

usually you'll deploy fastapi behind nginx or similar that will do https for you and then just proxy it back to the fastapi server running on uvicorn or hypercorn
here is an example configuration for such a nginx configuration: https://www.uvicorn.org/deployment/#running-behind-nginx
at the end of the page you'll also find how to deploy your fastapi code with https using uvicorn directly or uvicorn on top of gunicorn
higher up on the same page will explain why you might want to involve gunicorn in the tech stack

keen cosmos
#

i looked

ocean bay
#

@cloud spruce the goattt!! just wanna say a thank you to responding to me back when i was spamming the channel with beginner questions appreciate u bro!!

misty orbit
cloud spruce
cloud spruce
wispy spruce
ocean bay
cloud spruce
hollow gulch
#

hey anyone to take 20 mins debugging my code ? using zeroconf & socket

misty orbit
#
@router.get(path = "/v1/{method}")
async def get_methods(request: Request, method: str):
  if method == "method_1" # instead of having the endpoint "/v1/method_1"
    ...

is this a bad practice? I did it this way because all the methods in this particular function, are super straight forward, short processes.

ember ledge
#

Can someone help me with router on stick
So when im trying configure the router it say fa0/0.10 no vlan and the ip address if it don't have vlan it cant commiucate right?

cloud spruce
ember ledge
#

is this channel for internet networking or for neural networks?

pearl obsidian
#

internet networks

cloud spruce
hollow gulch
#

anyone knows about the zeroconf module ? i have issues with it

edgy jewel
#

Hello!
I need someone who can build an Asterisk server.
Please DM me.

waxen rover
#

Hello friends
Please help
OSI model ⬇️
data is broken into pieces called segments and packets are what holds the segments like a package?

cloud spruce
# waxen rover Hello friends Please help OSI model ⬇️ data is broken into pieces called segment...

Layer 4 = Transport layer, can be Segments (TCP and MPTCP are two examples) or Datagrams (UDP, SCTP and more)
Layer 3 = Network layer, Packets (IPv4, IPv6, ICMP, IGMP, PIM, IPsec, OSPF, RIP, VRRP, HSRP, among others)
Layer 2 = Data link layer, Frames (Ethernet protocol, Spanning tree protocol, ARP, LLDP, UDLD, CDP, 802.11 wireless LAN, MPLS, PPP for example)
Layer 1 = Physical layer (Wi-Fi, 5G, LTE, Bluetooth. as well as physical connectors, interfaces, cables, electrical signaling and levels for Ethernet, USB, DSL and so on)
each Ethernet Frame (L2) holds one Packet (L3) inside of it, some other layer 2 protocols such as HDLC can have multiple Packets inside one Frame
and in turn, each Packet (L3) can hold one Segment or Datagram (L4)

hasty quest
#

Each protocol carries some data that is internally used by the protocol above it.

#

Different protocols have different names for their units of data

#

It's important to realize that lower protocols often split and recombine data from higher protocols

#

So, one Segment (TCP) does not necessarily contain one Request (HTTP) etc.

#

How you break a data flow into pieces depends on what protocol you are looking at.

#

If you're talking about TCP, you will see different pieces than if you're talking about HTTP

#

TCP doesn't have to know anything about HTTP to break the data up. It just sees a big chunk of data that it splits into 4 parts, it doesn't care how that data is supposed to be split up at the "higher level"

#

This doesn't always happen. As rndpkt says, an Ethernet "Frame" always holds exactly one IP "Packet."

#

How things get broken up is very specific to the exact protocols you're dealing with.

#

Anyways, basically what you need to know about the OSI model is that every layer carries that gets interpreted by the layer above it.

#

If you send a request from your web browser to google from your computer connected to ethernet:

#

1 - Physical layer: Your physical ethernet card encodes data as electrical signals which are decoded by your router's physical ethernet card. These signals are used to send data for layer 2:

#

2 - Link layer: Your OS encodes data as an ethernet frame, indicating that it is for your router - your router should therefore read it, and any other computers can freely ignore it. These frames are used to send data for layer 3:

#

3 Network layer: your OS encodes the IP address for google, as well as your computer (for the reply) as an IP packet, indicating that the packet should be forwarded to google's IP address. These packets are used to send data for layer 4:

#

4: Transport layer: Your OS encodes a port, indicating to google's server which application it is trying to talk to, as a TCP Segment. This segment also includes information about the data stream itself, so that data can be received across multiple segments in the correct order. This is used to send data for layers 5-7

#

Here the model gets a big fuzzy. The OSI model is old and actually kinda wonky, so these layers often get combined since they are very vague.

#

But TLS (encryption) is built on top of TCP

#

and HTTP(s) is built on top of TLS or bare TCP.

#

You have to "unwrap" each layer to get data for the next one.

waxen rover
#

wow imagine if I asked what is a pencil
The only confusion I have "teacher Katy" is what is a segment and what is the difference between a packet and a segment. @hasty quest

hasty quest
#

Segments are a term used by Transmission Control Protocol (Transport layer)

hasty quest
#

An IP packet contains this information:

#

The "Data" in the IP packet may have a TCP segment inside it.

waxen rover
#

you told me the terms associated with packets and segments and also what it contains but my question I am asking is what exactly are they.
I know that packets arepieces of a whole information but don't know segments

#

If you can help pls