#networks

1 messages · Page 20 of 1

vernal surge
#

Like I said, it depends what you are doing. If you are hosting a "hackable" OS, you need a full os

dusk sparrow
#

given the number of services they're hosting , and the amount of traffic , that cost sounds very worthy

#

most of the challenges I suppose are running inside 16.04 dockers

vernal surge
#

I actually have insight into this field at I was a core developer on the US DoD cyber training range

dusk sparrow
#

wow that's amazing @vernal surge

#

can u give me an insight into how we can bring down the overall costs while still maintaining performance and a bit of scalibility also

vernal surge
#

For realism, we had to expose things without docker, because docker does enough stripping of the kernel syscalls to make it different. Unless your point is to train on exploiting containers, it's not sufficient to run a container.

#

But if you are very targeted with your goals (like just trying to exploit nginx for example) then docker works just fine

dusk sparrow
#

no no sir , we're just planning for basic exploitation stuff

vernal surge
#

In any regard, don't run a container in this context without kata containers

dusk sparrow
#

kata containers?

#

are they different from docker?

vernal surge
#

It adds a VM layer to further isolate the container from the host

dusk sparrow
#

is it more complicated than docker?

vernal surge
#

Not really

dusk sparrow
#

because we just need something as basic as docker itself

#

is docker not effective in this regard?

#

or is it too much?

#

im really sorry for sounding so dumb sir

vernal surge
#

I'm saying, if you're going to be exploiting it, or having others exploit it, you need to plan for them inevitably breaking out of your playground and causing havoc lol

dusk sparrow
#

yah that anyways we have sandbox right to prevent any breaches

#

in dockerfile

#

we add permissions right

vernal surge
#

Yeah, user locking things helps

dusk sparrow
#

so kata containers basically add another layer of protection?

#

are they more feasible and effective than docker?

vernal surge
#

In this case, if you just want to use docker, you could probably get away with just using ECS and letting Amazon handle the backend security and scaling

#

are they more feasible and effective than docker?
@dusk sparrow yes, by a lot

dusk sparrow
#

ohh nicee

vernal surge
#

Ecs is pretty cheap too

#

The other clouds have something like it as well, but the names escape me

dusk sparrow
#

yah , if we use kata containers for all services , will it be less heavy on resources and overall cost?

vernal surge
#

No, kata does add overhead, so technically, is less cost effective, but far more secure. I've found the cost difference to be negligible though

dusk sparrow
#

I think we can handle security ourselves , just need cheaper alternatives and less overall technical overhead

vernal surge
#

But with kata, you will have to run on a VM instance, so your cost will be effectively static anyway

#

I think we can handle security ourselves , just need cheaper alternatives and less overall technical overhead
@dusk sparrow use ECS then

dusk sparrow
#

how is ecs better than ec2 or kubernetes sir?

vernal surge
#

The scaling is handled for you, so it's less technical overhead

coarse epoch
#

im trying to set up vdi with hyper v, but when i try to connect, it just rdps me into the server and not one of the virtual machines, and the server gives this error

Error: NULL```
vernal surge
#

@dusk sparrow kubernetes isn't cheap, so it's probably out lol

dusk sparrow
#

The scaling is handled for you, so it's less technical overhead
@vernal surge can we tweak it to extract better performance?

vernal surge
#

Yes

dusk sparrow
#

like minimal scaling max performance

#

hm nice

#

maybe we can tweak all right?

vernal surge
#

You have a "task" that you set up that has all of those options

dusk sparrow
#

yah

vernal surge
#

Mix/Max replicas, min/max cpu/memory, etc...

#

@coarse epoch I've never had any luck with hyperv, so sorry, I can't help here

coarse epoch
#

np

vernal surge
coarse epoch
#

ty ill aks there

dusk sparrow
#

yah so , u suggested ecs , what about the others like ec2 etc?

vernal surge
#

Ec2 is fine, but you have to self manage everything, so more technical overhead

dusk sparrow
#

everything as in from scaling to tweaking ?

vernal surge
#

Yeah, literally everything

dusk sparrow
#

ohh , also , is ecs good for long term hosting , like for example I told right , the site that hosts exploitation stuff

#

in the end , what matters is the overall cost right

vernal surge
#

For a site, I would use Lambda+S3 or even just S3 if the site is purely static

#

That way is the most cost effective for sites

dusk sparrow
#

yah we're planning to have a portal for this purpose

#

so is S3 effective in that case?

vernal surge
#

Only if your site is static lol

#

If you have interactive elements (logins, etc...) You need lambda as well

dusk sparrow
#

well if we plan to have login pages etc then it has to be dynamic right?

#

ah yah

vernal surge
#

There are a TON of tutorials for that pattern though

dusk sparrow
#

so Lambda+S3 is better than ecs overall ?

#

cost being a major criteria here

vernal surge
#

Only for sites

dusk sparrow
#

hm yah

vernal surge
#

Lambda has no backend at all (that you can access) and S3 is just blob storage, so for your "challenges", that pattern is a non starter

dusk sparrow
#

I dont think our portal is going to be static , it would have login , scoreboard , and more stuff ig

vernal surge
#

Ok, so lambda+s3 for the site, ecs for the challenge hosts

dusk sparrow
#

hm yah

#

that sounds like it

#

thank u so much @vernal surge , I am really grateful to u for giving ur time for this discussion

vernal surge
#

All good, I've been down this road a few times lol

dusk sparrow
#

it is so delightful to get answers from a pro in the field , much appreciated sir

vernal surge
#

lol you are quite welcome

dusk sparrow
#

also , just one more thing , can ecs provide me with some kind of networking setup which can notify if services are down?

vernal surge
#

@dusk sparrow yeah, cloudwatch is actually good about that

dusk sparrow
#

is it a service offered along with the others?

vernal surge
#

yeah, everything i've mentioned is an AWS service

#

you don't really need to worry about that though so long as you have health checks set up

dusk sparrow
#

it can notify me whether my services are down?

vernal surge
#

if ECS sees a healthcheck fail, it'll just tear down that container and spin up a new one

dusk sparrow
#

waoh it does this automatically?

vernal surge
#

yeah

#

well ... it can 😄 but you have to configure it to do so (re: health checks lol)

dusk sparrow
#

yah thats doable

#

thank u so much once again

vernal surge
#

👍

vital kraken
#

anyone wanna be my cisco packet tracer buddy trying to get into this stuff

vernal surge
#

Lol oh boy, I haven't heard that name in a while.

#

I'm glad to help you out @vital kraken, but I'm going to pass on running PT lol

#

Studying for the CCNA R/S?

vital kraken
#

@vernal surge ccna but i cant blame you on passing up on the pt lol

vernal surge
#

@vital kraken I have my CCIE, so I can probably help :)

vital kraken
#

@vernal surge honestly im kinda looking for someone to go through the course with ya know not trying to get carried through it just so we can help each other as we go along

vernal surge
#

@vital kraken I totally get that, but if you get stuck, I'm around :D

vital kraken
#

@vernal surge sounds great mind if i add you?

dim wadi
#

could you get a job in IT with just a CCNA?

dreamy python
thorn stratus
#

@dim wadi I kinda doubt it, but look at job postings in your area and see what they are asking for

undone gust
#

so, still making a proxy, i've made the main part and the echo-server (so the echo-client is the only part left), and i changed the ports so i could test it on the same pc, anyway, the connection itself works, the server talks to the echo server that talks to the main proxy server, but if i send any message from the server (which it should be able to handle, that's the point), it crashes both the proxy server and the echo-server, the only exception is the first message that i receive manually, and even then it cuts off the first letter

#

i'll send some pastebin for the code i guess

#

some of it may seem nonsense or confusing, like all of the numbers i save, those are just ID's that i read to see what i have to do, like 1 is register connection, 2 is new connection, 4 close connection, etcc

#

(ping me if you can help me please)

loud flame
#

Hi everyone

#

I have found a script made in python which download some videos from a site

#

but it needs some improvments

#

here is the script

#

For example: the download progress bar does not working

#

extracting real names from the site, does not working well

#

you cannot select more courses to download

#

only one at a time

#

also the script can be improved to download a playlist and not only a course

#

i am not that good in python and that's why i am posting here

undone gust
#

well is it your own script?

#

@loud flame

loud flame
#

I was helping the guy who made it

#

Jayapraveen

#

helping with testing and cookies

#

But for a period of time , the developer seems that it cannot be found

#

don't know what happening with him

coarse epoch
#

im getting this error trying on the serer when i try to rdp into a virtualized desktop in hyper v
Remote Desktop Connection Broker Client failed to redirect the user ENTRUST\ja.

restive blaze
#

Get your IT guy to fix it

undone gust
#

LMAO

#

@restive blaze i bet he's the IT guy

#

and he has no clue how to fix it

glass turtle
#

I had an idea to connect two laptops together, one acting as a 'database' of files/programs without network access but if the other one (the primary one) downloads something, it'll go through to the other. Sort of connecting the drives, but one drive has a cpu/mem attached. How would I go around doing this? I was thinking potentially thinking about doing this over specific ports and getting the database one to only search for traffic on those ports but any other opinions would be appreciated

vernal surge
#

@glass turtle the "without network access" make what you want to do essentially impossible (not actually impossible, but pretty close), so I assume you mean without internet access.

glass turtle
#

Ya I mean I don't want it constantly connected to the internet, just when it needs to be

wraith grove
#

How does it know when it needs to be on the internet

tranquil fable
#

Does anybody here know if there is a way to get the source of a message sent with socket.sendto(message.encode(), ('<broadcast>', PORT))
Im working on something that's supposed to send and receives broadcasts at the same time and its quite annoying to get my own broadcasts.

wraith grove
#

as in get the ip your sending it from?

tranquil fable
#

The IP and Port

wraith grove
#

i believe socket.getsockname() does that

tranquil fable
#

I didn't bind the one im sending on:
broadcast_send = socket.socket( socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) broadcast_send.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) broadcast_send.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
So that gives me a OSError: [WinError 10022] An invalid argument was supplied

wraith grove
#

Why are you passing a 1 into that fucntion

#

lemme check the docs, iirc you don't need a 1 to set the option

#

guess I'm wrong

glass turtle
#

How does it know when it needs to be on the internet
I was assuming there's some sort of program to look for traffic on specific ports

vernal surge
#

@glass turtle yeah, you would write that :)

glass turtle
#

?

vernal surge
#

@glass turtle tbh, in order for a system to listen for traffic, it would have to be on the network at all times. And you can write your app to only listen on a specific port. But unless you wrote a custom ethernet/wireless driver that filtered everything at the kernel layer and only let your specific traffic pass, you are going to have to leave it on the network. You could use a firewall to limit exposure though.

glass turtle
#

would there be a way to cron a connection?

#

like only connect at a specific interval

vernal surge
#

You could cron firewall rules, and technically, yeah, you could cron up/down scripts

#

I just don't understand why you are doing this lol

glass turtle
#

like I want to have the 2 devices connected but I don't want the one I'm using for storage/extra computation constantly connected to my network

dreamy python
#

hi i need help with understanding what is the definition/connection of/between python-socektio and websocket
i found this quote->"Socket.IO is not an implementation of WebSocket, it is a different protocol that is implemented on top of HTTP and WebSocket both. A Socket.IO client can only connect to a Socket.IO server and viceversa. The WebSocket protocol is incompatible with Socket.IO."
not really sure if its corect...
i really would like for some explanation for python-socektio ,cause i thought socketio uses websockets...

vernal surge
#

@dreamy python it does use websockets, it says so. But it's a custom protocol built on top, so it does things differently than vanilla python websockets, and is therefore, incompatible.

dreamy python
#

ok so if im using python-socketio im actually using socketio protocol and not websocekts protocol?
and also what does it mean WSGI on sokcetio??

thorn stratus
#

@glass turtle why don't you want it constantly connected to the network? If you don't want to accept connections, don't listen on any poets

#

If you want it only accessible by a certain computer, then use firewall rules, or put it on the same private network

undone gust
#

@ember ledge here are the real experts, they can defenitely answer better than me peepoDance

ember ledge
#

lmao

#

anyways, is it possible to host server without port forwarding?

wraith grove
#

@ember ledge Generally, you are behind a NAT, which is a way to let a bunch of devices in your home network share 1 public IP, by creating a private network and using ports to tell what goes to which computer. You need some way to have a public IP go to your computer. You can use port forwarding, certain VPNs, or host the server on the cloud if you can't port forward on your home network

ember ledge
#

hmm

#

on the cloud servers

#

is it possible to forward in there?

wraith grove
#

Yeah, generally they will either give you a public IP or some ability to port forward

#

depending on the service

#

this one is great, the $3.50 one should do fine for low-traffic servers

#

pretty intuitive too, you can ssh from the console

vernal surge
#

@ember ledge no need to forward on cloud usually because you get an actual public IP

dreamy python
#

ok so if im using python-socketio im actually using socketio protocol and not websocekts protocol?
and also what does it mean WSGI on sokcetio??

@dreamy python
Somebody got an answer

gloomy root
#

WSGI is a interface standard for python webservers

vernal surge
#

@dreamy python yeah, what @gloomy root said. WSGI is just the standard way for a web server to interface with a python web app. Some use Gunicorn or uWSGI, other use the Apache plugin directly, others the nginx plugin.

#

And ASGI is just the async version of WSGI

gloomy root
#

very different in terms of the interface itself tho

#

Personally i prefer the ASGI interface

#

just seems a bit cleaner and more consistent

vernal surge
#

Agreed

gloomy root
#

tho ngl in my recent tests

#

the who ASGI and WSGI style of breaking it up into chunks

#

has caused significant bottlenecks for me lol

#

tho i think its down to something not syncing up or something timing out

vernal surge
#

Yeah, I honestly don't use python for web anymore because of those pitfalls

gloomy root
#

atm Im using Go lang and Fasthttp to make a prod grade server that binds to python on a raw connection

vernal surge
#

Go ftw

gloomy root
#

on windows its about 2x the speed of the current systems but thats mostly because Uvloop doesnt work on windows

vernal surge
#

I user either Go or Rust depending on the task

#

But yeah, I'll loop python in for math things

gloomy root
#

tho Still about 40% performance increase on linux overall

#

also has the advantage of not depending on Nginx or apache to serve static files properly and protect the instances

#

😎

vernal surge
#

I still use nginx lol, but just as an AppFW for the most part now ... Or if I'm running multiple servers

gloomy root
#

What i'd like todo at some point with the system is let them be either independent of mergeable

#

So if you have a single server it works as normal but multiple servers for multiple domains merge into serving all domains and servers just directing the request to specific python workers

vernal surge
#

Sounds interesting, although nginx does that lol

gloomy root
#

yeah ik

#

Most of it is for fun / for my exam but always nice to add somethings that id find useful

#

that and i low key cba to setup nginx's proxying

vernal surge
#

For sure... It's really useful especially if your aren't allowed to use nginx or whatever for some reason

#

Writing proxies is why I learned go in the first place lol

gloomy root
#

I think Networking is what makes Go so good tbh

#

as well as the short compile times

#

Leveraging OS threads to their full potential makes Networking uber easy and scallable with go

vernal surge
#

Yup, it's a hyper-scale language by design

#

Although, it does break down for real time stuff (GC is bad for real time lol)

gloomy root
#

The only thing i'd like to see which would make Go insane would be better single threaded concurrency per os thread

#

the runtime manages maybe 2-4 goroutines to one os thread

#

but you could easily stack more onto them for non-blocking networking stuff

vernal surge
#

They are making some nice inroads there with the new linker though. I'm interested to see what comes of it

gloomy root
#

One of the reasons that made me like Tokio is the choice of setup for concurrency

#

single threaded scheduler for light weight io stuff

vernal surge
#

I like tokio, but damn it's complex lol

gloomy root
#

or threaded scheduler which can deal with more heavy stuff

#

tokio is fairly complex

#

tho its alot better than actix

#

actix's system is a bit of a blurr

#

I think the actor system could of been done a bit cleaner

vernal surge
#

Yeah, I never got actix to work as described

#

And there was just way too much rewriting of the STDLIB

#

Idk, I'll take a nominal performance hit for the safety guarantees. If I only cared about raw performance, I'd just use c lol

gloomy root
#

Actix is the most awful thing ever to compile

#

it has so many Weird things with it

#

Like installing GCC to windows is one thing

#

but its when it compiled in Debug mode fine

#

but then when in release it doesnt compile because of some weird error

#

just urg

#

too much effort

#

Hyper or Warp tho are pretty <3

left maple
#

I think ARP is networking, but idk.
Im trying to do an ARP request, and I got the error:
ImportError: cannot import name 'ArpRequest' from partially initialized module 'arprequest' (most likely due to a circular import) (c:\Users\path\to\python\file)
Here is the code im using:

from arprequest import ArpRequest
ar = ArpRequest('10.0.0.1', 'eth0')
ar.request()
ember ledge
#

anybody got a good alternative for the requests module?

#

i want to send about 100+ requests per second, tried threading while using requests but it didn't work as expected

shy pebble
#

You probably want async for that, try aiohttp

ember ledge
#

Noted

wraith grove
vernal surge
#

@left maple sounds like you didn't supply enough arguments to initialize the object

versed berry
#

I need some help with network setup

#

I'm not a network engineer and I have a business connection from my ISP with 2 IP address. I want to use the 1st IP for standard connection and I want to use the 2nd for hosting a small server. I have a Juniper EX3300 switch I can use but I'm not sure it is the right thing to put between my wifi router (for normal use), and the server. Does anyone know if this is sufficient. The wifi router has a firewall. The server I'm hosting I don't want a firewall as it is supposed to be a honeypot.

#

Also, I wanted to setup another server on a 3rd IP to be a VPN, but that is kind of getting ahead of myself at this point.

proper plover
#

anyone used POAP? for configuring bare metal nexus devices?

sage storm
#

How can I target a multicast for nodes on a VLAN? This code works for nodes on LAN.

import socket

PORT = 23333

def startRelayServer(players):
    hostRecv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    hostRecv.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST or socket.SO_REUSEADDR, 1)

    try:
        hostRecv.bind(("", PORT))
    except Exception as e:
        print("Port has been occupied, please run the script before hosting the game.")
        return

    players = [player for player in players if player != ""]
    socks = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in players]
    print("Relay server started, now host your game.")

    while True:
        for i in range(len(players)):
            hostData, hostAddr = hostRecv.recvfrom(1024)
            if len(hostData) > 0 and hostAddr[0] not in players:
                socks[i].sendto(hostData, (players[i], PORT))
                print(f"Broadcast package received, sending to {players[i]}.")

if __name__ == "__main__":
    players = ["10.8.0.3", "10.8.0.4", ""] # Player IPs
    startRelayServer(players)```
left maple
#

@left maple Did you name your file arprequest.py
@wraith grove yes its called arprequest.py

@left maple sounds like you didn't supply enough arguments to initialize the object
@vernal surge I copied the code straight from the docs lol

vernal surge
#

@left maple unfortunately, you can't always rely on the docs.

#

But yeah

sullen iron
#

I would like to make a passthrough proxy, which I will use with proxychains, to pass all my browser traffic through. However I'm not sure how to forward the packets back out, and why I am unpacking ethernet frames on wifi

arctic barn
#

maybe kind of a stupid question that possibly doesnt even belong here but - how does a modern smartphone app, say on an iphone 10, communicate to a server (something that hosts the apps online interface)? what protocol does it use, what formats can it send its message in, what hardware converts it to an airborne message?
this is maybe a question that is better answered via redirection to a networking beginner resource and id truly appreciate that too!

flat ermine
#

!NOT AN EXPERT; MIGHT CONTAIN DANGEROUS HALF-KNOWLEDGE
@arctic barn most websites and afaik some apps as well communicate using a REST api (google that, if you plan to ever do something web related it will come in handy). A package of a messager app might contain:
-the type, could be POST if you want to post a message or PATCH if you want to edit your message. Lets go with the case of you posting a message
-the sender, you
-the recipient
-the message itself
-a token that authenticates you as the real user

protocol - depends on the app or website. many services use HTTP(S), but different programs use different protocols and ports - SMTP for example is for mail, but I am not sure if it is still used.

how hardware converts stuff - thats a completely different topic. I would refer to the OSI-7-Layer-Model. The principle is the following (this is all from what I remembered, some things might be wrong): They have a payload, your data you want to transfer. This payload gets wrapped with headers. Every Layer reads its header (which is always in front), decides what to do with it based on the header and then sends the package to the layer below it and removes the header that it read. This continues all the way until you are at the bottom layer which then sends the package to the specified server (DNS, another topic again). Once it has reached its destination, the package goes through the layers the other way around

arctic barn
#

thanks so much for taking the time to write this! i’ve heard of the REST api but never looked at in detail, so i certainly will, and i’ve never heard of the OSI model. i couldn’t have asked for a better response, tysm <3 <3

flat ermine
#

I do have a question as well tho, not sure if it is even possible to do it this way:
I have the following setup:
PC - Switch - Router
192.168.188.20 - 192.168.188.1 - 192.168.2.1
problem is - how do I directly connect to the router from my PC? I can only reach the switch, if I try to connect to the routers IP it gives me an ERR_CONNECTION_TIMED_OUT

I tried tracerouting to be sure I have the right IP;
1 <1 ms 1 ms <1 ms fritz.box [192.168.188.1]
2 1 ms <1 ms <1 ms 192.168.178.1

wraith grove
#

@left maple If you didn't figure it out, its because you are importing the file that is running

#

rename your file to something else and it will work

tiny idol
#

this might be a bit of a stupid question, but does anyone know how to port forward to a docker on a remote server? I know for local to remote I just ssh tunnel with -L XXXX:localhost:YYYY, but to access the docker is a lot more challenging. Would I have to go from:
docker -> remote -> local? or could i skip it and just go from
docker -> local? The reason why i need this is that i need to access a login page on the docker but there's no gui, so i want to port forward that login page onto my local computer.

eager karma
#

oof

wraith grove
#

@tiny idol It seems like you aren't quite understanding what port forwarding does. Are you trying to access a page served from the docker?

tiny idol
#

Yes. But on the machine running the docker all it has is terminal. So I'm trying to forward it to my personal computer

#

I've done it before with forwarding jupyter notebook from my remote to my local so I'm hoping it's the same thing

#

My bad if I sound really ignorant about this.

wraith grove
#

how are you accessing the docker right now

#

You need to port forward so the router knows which computer to give incoming connections

#

if your docker isn't behind a router, then you don't need to port forward, just open a port in your firewall if you are running one

#

if it is, you need to port forward on the docker side, since you will be connecting to it

tiny idol
#

My docker is not behind a router. I'm accessing the docker through my remote machine right now. I think what it is, is that I've been working a lot with virtual machines, and all of a sudden my project requires the use of a docker and it's super confusing to understand.

I'm currently running docker stack deploy -c charts-docker-swarm-19.12.2.yml mongodb-charts for my docker.

It's supposed to open a web gui on localhost:80 but since my remote server doesn't have a browser, I can't do that.
I assumed that if I tunneled port 80 from my remote server onto my local server, i would be able to open the browser on my local,
but it's not loading so I'm assuming the networks for the docker and the remote are separate.

#

i've tried opening firewall ports with ufw on port 80 but it didn't work

wraith grove
#

How did you connect to the web gui

#

from the remote

#

are you typing localhost:80?

#

Just put the ip of the docker in your address bar

tiny idol
#

i believe it is localhost:80, but i have never made a connection because on my remote there's no gui.

#

which is the reason why i'm trying to port from the remote to my local so i can open it up on my own browser

#

i think it would make more sense if i put the ip of the docker into the browser, but i haven't been able to test it out.
I assume that 172.17.0.1:80 would open up the web gui instead, but how could i send that to my local machine?

tiny idol
#

@wraith grove i appreciate the help and the advice for what to look into. I do think my question is a bit out of place as it's more of a Docker question than a networking question. But some of the things you brought up were helpful! I was able to further pinpoint the problem with no resolution quite yet, but I'll be looking into a Docker community that might have more insight on the situation.

wraith grove
#

localhost just means the computer your on

#

if you are trying to access a remote computer, you use its ip

#

What are you confused on sending to your local machine

deft ibex
#

They are implementing at&t fiber in our neighborhood. there was a hole being digged right in front of our house and that's how it was figured out 😄

sullen iron
#

I want to make a wireshark-like packet sniffing proxy in python, ideally something I could append to proxychains.conf, and analyze my traffic in real time. I've done some searching around and found this: https://www.tutorialspoint.com/python_penetration_testing/python_penetration_testing_network_packet_sniffing.htm, however I'm not sure where the data is coming from

scenic steeple
#

what's Encrypted SNI ?

simple flax
#

I have a very general question about networking. Is it better to establish a socket tcp connection to your server then just send data over or to create an api for your server and instead send post request? What is the most common way and what's better in terms of performance?

north quarry
#

hey question im making a chat app with sockets, but how can i make the difference if a client is sending a file or just a normal text message?

#

because now i get the issue that its saying invalid start byte at position 0

vernal surge
#

@north quarry If you are just streaming raw bytes over the network, you can't possibly know. When you are starting to switch back and forth between data types, it's best to structure your communications and/or use an RPC paradigm

#

@simple flax raw sockets are always going to be faster than having to marshal/unmarshal JSON/XML, but in terms of what is common, JSON 100% (so your typical RESTful app)

#

@simple flax 100% depends on what you are doing though

north quarry
#

@vernal surge how could i bbest handle that?

vernal surge
#

@ember ledge is your server running on the same machine as your client?

north quarry
#

no idea how to do that xd

vernal surge
#

so, you could wrap everything in JSON before you pass it over the socket with different fields for different data, that way, you code knows how to interpret what it's getting

#

not saying that is the best way to do this, but it's probably the easiest lol

north quarry
#

its just a very basic program, with threading . just sending chat messages, but i want to be able to send a file maybe with pickling

#

need to finish this school assignment XD

vernal surge
#

ah, this is for an assignment? I've said too much then lol

north quarry
#

nah its okay xd,

#

doing more then i should

#

so xd

simple flax
#

Thanks for your response @vernal surge . Since using APIs are common is there any reason why companies dont use raw tcp connections if its faster (more safe??)

vernal surge
#

nothing wrong with a little over acheivement lol

#

@simple flax the reason most companies don't use just raw sockets is due to the complexity of parsing out an unknown data stream. In JSON, the format is well defined so server knows how to process the data regardless of who sends it (and it rejects anything that doesn't conform)

simple flax
#

I see. But you can send jsons over raw sockets, no?

vernal surge
#

now, that being said, there are times when sockets/websockets are the best solution (mostly when you are the one that built the server/client and you know for sure what the data is going to look like)

#

yes, you can send json over sockets, but that may or may not be any more efficient that just using dedicated json libraries

#

again, it's all use case 😄

simple flax
#

If you're writing a website then it might make more sense to use json but im writing a desktop app and I think it will be better to use sockets

vernal surge
#

that is honestly why gRPC is starting to really take off ... you get the performance of byte-stream communication, but the distributability of JSON

simple flax
#

I see

#

It's just harder to store an api key on client side

#

If the client gets it then nothing stops him from spamming the api

vernal surge
#

not true exactly ... i NEVER write a public API that doesn't have rate limiting enabled 😄

simple flax
#

Yeah rate limiting would work

vernal surge
#

most APIs you see now are just general messaging, so there is really no benefit to using a raw protocol. The only reason I see raw sockets in use right now is usually due to a custom protocol

#

but then again, my visability into the global use of sockets is limited lol (i'm just a lowly SRE lol)

#

but in my world of containers and kubernetes ... gRPC is king right now, with JSON a close second

simple flax
#

Yeah right. And you don't have to worry about sending the json in an encrypted form, since if the api use ssl then everything would be encrypted, or am I wrong?

#

Would sniffing be a problem

vernal surge
#

right, i didn't even consider encryption, but yes. Just simply using TLS on your webserver guarentees encryption wereas, sockets, not so much lol

#

again, TLS is my default, so i don't even really think about it any more

restive blaze
#

Websocket is pretty popular along with gRPC

#

Few people do raw socket. Probably just games at this point

#

We have one thing that needs real time. It’s web socket

vernal surge
#

I seem to see WebRTC in use these days as well, but I know nothing about it

restive blaze
#

JSON is payload inside wss

#

WebRTC is voice/video

#

I’m sure you could do data but it’s not designed for that

vernal surge
#

right, A/V is the only thing i know that really need real time streaming right now, but again, my perview of the arena is limited lol

restive blaze
#

Like Google Meet is WebRTC for audio and video with wss for control

#

Got stuck helping messaging team

vernal surge
#

interesting ... as it seems that 98% of the questions in this particular channel are socket/websocket related ... i probably ought to bone up on them lol

#

or just defer to you Rabbit lol

restive blaze
#

Nah

#

I’m not good at details just high level

#

My default response would be stop using sockets

vernal surge
#

haha, same

restive blaze
#

If you need real time communication, websocket it

#

In fact, a lot of IoT devices use websocket

ember ledge
#

most iot don't even have readlink() sad

vernal surge
#

i've not done anything IoT with websockets, usually just MQTT or something of that nature

restive blaze
#

Just my observation of IoT devices

#

We do a lot of message passing at work. AMQP

vernal surge
#

RabbitMQ or pure AMQP?

restive blaze
#

Pure, Azure ServiceBus

vernal surge
#

gotcha, Azure is one of those things I just can't bring myself to learn. I still just have that deep seated hatred for Microsoft lol

vernal surge
#

@ember ledge i think you may have ignored my original question re: this. Where are you running your server vs where are you running your client. If they aren't on the same machine, "localhost" doesn't work

#

also, you need to make sure your firewall isn't actively blocking 8080

#

also, it's nice to meet you Ayyan Shahid @ember ledge lol

#

it was in your copy-paste 😄

#

but also, I can't help you if you don't answer my questions @ember ledge

#

So you don't want help? did you fix it or were you hoping for someone to magically be able to tell you what is wrong without any information?

restive blaze
#

j4ng5y, another example of "WHY SOCKETS, WHY?"

gloomy root
#

speaking of

#

would sending 2 WS responses compared to 1 WS response legitimately cause 90% performance loss?

sullen iron
#

How would I go about making a python proxy? I usually don't ask so vaugely, but I am entirely lost, all the search results are either shills, or using plug and play libraries. I'm trying to say pass some traffic to it on port x and unpack it with struct, similar to wireshark

gloomy root
#

you should probably start with reading up on some of the general concepts of proxies in general rather than directly with python

#

Tho python i wouldn't say lends it self directly to being used to make proxies its certainly possible but not without alot of low level socket work

vernal surge
#

would sending 2 WS responses compared to 1 WS response legitimately cause 90% performance loss?
@gloomy root I would think not, but I assume you are seeing as much

sullen iron
#

That's the idea

#

I understand the concepts well enough

gloomy root
#

😅 Oh yeah, its dropping requests like flies and debugging between two languages is a nightmare

sullen iron
#

Here's what I have so far

#
#!/usr/bin/env python
import socket
import struct
import binascii
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
while True:
    packet = s.recvfrom(2048) # takes buffer size
    ethernet_header = packet[0][0:14]
    eth_header = struct.unpack("!6s6s2s", ethernet_header)
    print(f"Source: {binascii.hexlify(eth_header[1])} -> Destination: {binascii.hexlify(eth_header[0])}")
    ipheader = packet[0][14:34]
    ip_header = struct.unpack("!12s4s4s", ipheader)
    print(f"Source Ip: {socket.inet_ntoa(ip_header[1])} -> Destination Ip: {socket.inet_ntoa(ip_header[2])}")
#

Ouch

#

One second, god awful formatiing

gloomy root
#

i hope thats not all one line 🤣

vernal surge
#

i can't even imagine trying to write a proxy in python ...

gloomy root
#

yeah i wouldnt say its as simple as others

sullen iron
#

That should be better

gloomy root
sullen iron
#

I saw that

gloomy root
#

there is alot

sullen iron
#

I was thinking something more lightweigt

#

I'm not looking for encyption etc

#

More of just a passthrough

#

"like wireshark"

vernal surge
#

just a learning thing? i was just thinking "why not use wireshare or tcpdump or something"

sullen iron
#

Didn't look all too complex

vernal surge
#

legit, when i do pentesting things, i always use Go for proxies and such

sullen iron
#
#!/usr/bin/env python
import socket
import struct
import binascii
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
while True:
    packet = s.recvfrom(2048) # takes buffer size
    ethernet_header = packet[0][0:14]
    eth_header = struct.unpack("!6s6s2s", ethernet_header)
    print(f"Source: {binascii.hexlify(eth_header[1])} -> Destination: {binascii.hexlify(eth_header[0])}")
    ipheader = packet[0][14:34]
    ip_header = struct.unpack("!12s4s4s", ipheader)
    print(f"Source Ip: {socket.inet_ntoa(ip_header[1])} -> Destination Ip: {socket.inet_ntoa(ip_header[2])}")

Code from before

gloomy root
#

Go or Rust

sullen iron
#

This just intercepts all traffic?

gloomy root
#

Hyper has a really nice and simple Proxy system inbuilt

sullen iron
#

Or something like that

#

Give it a run to see what I'm talking about, please

gloomy root
#

Pretty sure the stdlib socket module doesnt have PF_PACKET as a thing

ember ledge
#

im running a threaded scan of the network but

#

i dont think my thread catches all the ones i want

#

because xxx.xxx.xxx.30 is online but wont show even though it should

vernal surge
#

this channel goes through weird trends lol

ember ledge
#

lol

gloomy root
#

i think its one of those areas where its alot more advanced than people think

ember ledge
#

who

#

lol

gloomy root
#

the channel

ember ledge
#

ahh

#

i read that wrong sorry

#

lol

#

ooh i found a better way

vernal surge
#

i think its one of those areas where its alot more advanced than people think
@gloomy root Ahh, i'll just put localhost everywhere .... WHY U NO WORK?!

gloomy root
#

god i remember when i was originally using localhost over 127.0.0.1 and getting absolutely fucked by latency issues and wondering what was causing it

vernal surge
#

lolol

gloomy root
#

such a hair tearing moment

vernal surge
#

i'm super glad that I started my career as a network engineer ... can't tell you how many times that knowledge has saved my ass

faint cairn
#

how can i connect to a socket server with a dynamic ip

faint cairn
#

Pls halp

north quarry
#
class Server(threading.Thread):

    def __init__(self, host, port):
        super().__init__()
        self.connections = []
        self.host = host
        self.port = port
        self.address = (host, port)

    def run(self):
        server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_sock.bind(self.address)

        # max_of_5_clients
        server_sock.listen(5)
        print("[*] The Server is listening for connections...")

        while True:
            # Accept new connections
            client_socket, sockname = server_sock.accept()
            print(
                f"[*] Accepted a connecction from {client_socket.getpeername()} to server on {client_socket.getsockname()}")

            # Create new thread
            server_socket = ServerSocket(client_socket, sockname, self)
#

class ServerSocket(threading.Thread):

    def __init__(self, client_socket, sockname, server):
        super().__init__()
        self.client_socket = client_socket
        self.sockname = sockname
        self.server = server

    def exit(self):
        print(self.server.connections)

        while True:
            ipt = input(">")

            if ipt == "!q":
                print("[*] Closing all connections....")
                try:
                  # I GET THE ATTRIBUTE ERROR RIGHT HERE....
                    for connection in self.server.connections:
                        connection.client_socket.close()
                        os._exit(0)
                except AttributeError as e:
                    print(str(e))

#

can anyone help me why i get the following error

#

print(self.server.connections)
AttributeError: 'Server' object has no attribute 'server'

#

i dont get why is it saying this

#

because im passing the Server object

#

so it should be able to access the attribute

vernal surge
#

@ember ledge to didn't actually provide an IP address 😄

#

@faint cairn best way is to set up dynamic DNS and point to that rather than an IP address

faint cairn
#

Ok Thx

vernal surge
#

are you trying to connect to the bridge or the light?

faint cairn
#

Is YDNS a good dynamic dns provider?

vernal surge
#

never heard of it

faint cairn
#

Can you recommend one for me?

vernal surge
faint cairn
#

Is it free tho?

vernal surge
#

no, but most of the trustworthy things aren't lol

faint cairn
#

😭 ok

vernal surge
#

i think that one is free and i've used it before

vernal surge
#

so it should be able to access the attribute
@north quarry so, this is why I don't like assigning class arguments like you did it in init, i would normally do a function to do that assignment:

class ServerSocker(threading.Thread):
  def __init__(self, client_socket, sockname, server):
    super().__init__()
    # define all class attributes
    self.client_socket = None
    self.sockname = None
    self.server = None
    self._parse_class_arguments(client_socket, sockname, server)

  def _parse_class_arguments(self, client_socket, sockname, server):
    # Doing it this way allows for you do to validations on the provided arguments, rather than expecting that they are correct
    try:
      # do things that validate your args are valid ... checking None probably isn't the only thing you want to do lol
      if client_socket is not None:
        self.client_socket = client_socket
      else:
        raise Exception("client_socket can't be None")
      if sockname is not None:
        self.sockname = sockname
      else:
        raise Exception("sockname can't be None")
      if server is not None:
        self.server = server
      else:
        raise Exception("server can't be None")
    except Exception as e:
      print(e)

...
vernal surge
#

Lol, you were so careful not to let us see your IP address too@ember ledge

#

Can you send a post outside of python to 192.168.1.104/api?

gloomy root
#

you really should care btw :P

#

without le proper precautions

vernal surge
#

But also, not sure you actually addressed the username bit I was getting at earlier

#

Idk, I don't use hue's, but I think he mentions that in the GitHub comment

#
one example is b=Bridge("192.168.0.20","sew45dsre3435esdwe")
To find the username on a hue bridge on a local ethernet, open the https://discovery.meethue.com/ and write down the id.```
#

@ember ledge

gloomy root
vernal surge
#

No, you are trying to connect to a bridge. @ember ledge

#

The API in something else is going to be different

#

What is it even that you are trying to connect to then if these things are BT only?

#

I know what you want to do, but what is the 192.168.1.104 device you were trying to connect to

#

If not a bridge, what is it

#

... so it isn't bluetooth then?

#

Or it's both?

#

Bluetooth doesn't use ip addresses

gloomy root
#

can you send us a link of said light bulb

#

cuz this is getting confusing with very contradicting systems

vernal surge
gloomy root
#

okay

#

so Each bulb must be linked with the Hub to control

#

seems the Hub is what actually controls said light bulbs

#

So connecting to them individually is gonna be pointless

#

They lock the api docs 😔

#

means i gotta scroll through my emails

#

right

#

this is what we're gonna be referencing

vernal surge
#

I ain't signing up for that shit lol

gloomy root
#

low key BS that they make you sign up just to read the docs

vernal surge
#

Which means that the docs arent free. They cost my contact info. What stupid marketing firm made that suggestion ...

#

I hate it when companies gain significant market share

#

Anyway, no more rants, sorry

errant bayBOT
#

Hey @gloomy root!

It looks like you tried to attach file type(s) that we do not allow (.html). 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, .m4a.

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

gloomy root
#

Grr python

#

if you're gonna make me use a paste bin atleast give me enough space to paste it 😔

#

@vernal surge if you want a copy of the html 🤣

vernal surge
#

;) thank you lol

gloomy root
#

In terms of how its gonna work

#

seems you need to send the requests to the light's hub/bridge

#

which then controls the lights like that

#

python -> bridge -> individual lights

#

🤔 Alexa's API is completely diffrent from the lights themselves

vernal surge
#

Alexa can be a zigbee bridge

#

But yeah, now we are taking about interfacing with Alexa, which is a whole other rant lol

gloomy root
#

im pretty sure looking at this to control the ApI directly it forces you to get the hub

#

seems alexa has all the BT systems pre installed as a sort of partnership

vernal surge
#

The Bluetooth I'm sure allows the mobile app to communicate directly though, but I don't see any reference to that api

gloomy root
#

they're not very clear on these docs tho

vernal surge
#

So you would be reverse engineering it lol

gloomy root
#

not as bad as google tho

#

right

#

Do you have this 'bridge' thing?

#

apparently this is the needed

#

so probably using alexa's api is gonna be easier

#

and we can just bully Alexa into bullying hue

vernal surge
#

No way to use python then unless you reverse engineer the Bluetooth calls and then use a bluetooth library. But that will not be trivial.

gloomy root
#

i kinda want todo that now

vernal surge
#

Lol

#

I wouldn't use python for that

#

But yeah

gloomy root
#

probably go with rust

vernal surge
#

I mean, like @gloomy root said, it's possible to do some hacky things with the Alexa api, but there is no good, direct, library for you to use @ember ledge

gloomy root
#

I shall stick one of those in my shopping basket and document my adventures 🤣 for £14 its not too bad, not after spending £60 on a single maths book for school

vernal surge
#

Lol, I look forward to the write up

gloomy root
#

only small issue is i dont have a Bluetooth reciever or sender on my pc 🤔

vernal surge
#

Raspberry pi has a built in

#

It's what I do most of my hacky hardware stuff with lol

#

Because I don't care if it dies lol

#

Laptop on the other hand... I need that not to die lol

#

Paid way too much money for it

undone gust
#

hey guys i get errno32 broken pipe and i'm not sure why, i'm making a proxy and after connecting everything, i send 1 message from the server to the echo server to the proxy (the first one is handled differently from the others) to register the server connection, but any other message i send from the server (as in: if i try after the first message) breaks the echo server and gives errno32 broken pipe

#

i'll send the code

errant bayBOT
undone gust
#

oh

#

i fiddled with the ports to be able to run this on 1 pc for testing

gloomy root
#

what OS is this?

undone gust
#

well now i'm on ubuntu

#

i can try to run it on windows if you want

gloomy root
#

i doubt that will run on windows

undone gust
#

want me to also send a random server and client program?

gloomy root
#

Windows is very picky

undone gust
#

well i mean i made most of the program on windows

#

and switched to linux very recently

gloomy root
#

also dont use CONSTANTS_NAMING on things you're modifying

#

it just gets confusing

undone gust
#

i just had to fiddle permissions

#

wait uppercase is used for constants?

gloomy root
#

yes

undone gust
#

oh

#

sorry :3

#

i'll note that thanks for the tip

gloomy root
#

CONSTANTS

_private_thing

avoiding_naming_colisions_

Classes

#

those are pretty much the standard naming conventions in python

undone gust
#

ok

#

thanks

#

i knew about all of 'em but the constants

#

well umm, so should i also juts send a random client and server program? the proxy itself is made to not be picky (hence the echo server and client, they handle all the 'custom protocols' i made so that you dont have to implement them), but yeah it might save you time

gloomy root
#

what line does it say the broken pipe is ocouring?

#

send le stacktrace

undone gust
#

a random line where it does a receive, i'll reproduce it now

#

oh wait i just got.. a different error?

#

it crashed on the very first message which is handled a bit differently

#

echo server's error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "echo-server.py", line 57, in handle_proxy
    msgid = int.from_bytes(proxy.recv(1), "little")
ConnectionResetError: [Errno 104] Connection reset by peer
^CException ignored in: <module 'threading' from '/usr/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt:
#

main proxy's error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "proxy.py", line 139, in handle_conn
    handle_pack(conn)
  File "proxy.py", line 82, in handle_pack
    log.info("Registering conn: %d", CONNIDS[conn])
KeyError: <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>
#

huh, his isn't what i got before

#

OH WAIT, i remeber! afte some changes i stopped getting broken pipe and got this instead, but broken pipe occured on the second message and this occurs on the first one, so if this was fixed i'd also have to deal with the other one

gloomy root
#

you appear to be trying to hash the entire socket object

undone gust
#

what does hashing mean

gloomy root
#

turning it into random numbers would be the simplest method to describe it

#

but dw about that for now

undone gust
#

encoding?

gloomy root
#

I would assign the conn_ids to have string keys not entire objects

undone gust
#

connid's should be a number

#

like the first client that connects gets 1, the second 2, etc

gloomy root
#

well in that error conn is the socket itself

#

and you're trying to index CONNIDS with conn itself

undone gust
#

yeah cause i have a list where conn is the key and connid is the vale

#

in CONNIDS, the key is the connection itself, and the connid is the value

#

is that wrong?

gloomy root
#

i wouldnt say its advisable

undone gust
#

is it just because it's long, or because of it being a conn itself

#

because if it's the second choice i could just str(conn) and use that instead right

gloomy root
#

it just seems like a awkward system for the sake of getting a number

undone gust
#

well that number is quite important

#

i don't have any other ideas, the connection is reliable because i always have it while i receive, if i didn't use that then idk

#

i could store the connid on the echo server/client and send it directly? does that sound good?

#

like instead of deriving the connid by the connection, i just send the connid, i had thought of that but... that lets people fake their connection and tamper with other's connection

gloomy root
#

but couldnt you use a incremental counter rather than that

undone gust
#

i do use it

#

i assign the connid in the main proxy thingie, all of this is just to derive it so that i can send it to the server

#

like i assign every connection its connid and every one is 1 bigger than the one before, starting at 0, so incremental

#

:<

gloomy root
#

hmm

#

I cant look into it much more because im about to sleep

undone gust
#

yeahh i think this project was a bit out of my reach, but i tried anyway, and made a cluster fuck

#

well most of it worked, so that's nice

gloomy root
#

but i think it would be simpler to make a class and give the class it's id so it knows what connection it is

undone gust
#

to do that wouldn't i have to rewrite the entire thing

#

also i'd have to find a way to call every class i create differently which i'm not sure how to do

primal scaffold
#

How to send email only with standard library ? Without using smtplib or any other libs

half urchin
#

I'm not sure if this is the correct channel, but I need to create something like TeamViewer that will, when the button from the phone, include the following videos on YouTube (I want to know which libraries can make the process easier)

north quarry
#

anyone that can help me why i get an AttributeError

#

# both classes are in own files!


class ServerSocket(threading.Thread):

    def __init__(self, client_socket, sockname, server):
        super().__init__()
        self.client_socket = client_socket
        self.sockname = sockname
        self.server = server

    def exit(self):
        while True:
            ipt = input(">")

            if ipt == "!q":
                print("[*] Closing all connections....")
                try:
                    # THIS THE LOCATION THAT CAUSES THE ERROR
                    for connection in self.server.connections:
                        connection.client_socket.close()
                        os._exit(0)
                except AttributeError as e:
                    print(str(e))


class Server(threading.Thread):

    def __init__(self, host, port):
        super().__init__()
        self.connections = []
        self.host = host
        self.port = port
        self.address = (host, port)

    def run(self):
        server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_sock.bind(self.address)

        # max_of_5_clients
        server_sock.listen(5)
        print("[*] The Server is listening for connections...")

        while True:
            # Accept new connections
            client_socket, sockname = server_sock.accept()
            print(
                f"[*] Accepted a connecction from {client_socket.getpeername()} to server on {client_socket.getsockname()}")

            # Create new thread
            # Here im passing self ( this is the Server class)
            server_socket = ServerSocket(client_socket, sockname, self)

            # start new thread
            server_socket.start()

            # add thread to active connections
            self.connections.append(server_socket)
            print(f"[*] Ready to receive messages from: {client_socket.getpeername()}")
#
AttributeError: 'Server' object has no attribute 'server'```
dreamy python
#

Hi in Which layer of osi model operates socketio protocol?(i read that websocket is on 7 layer)Im trying to understand the flow cause socketio is on the top he uses beneath him websocket which uses http/TCP protocol right??

gloomy root
#

Websockets are built ontop of a upgraded HTTP GET request, which intern is built off the TCP protocol

dreamy python
#

Ok so actually inside TCP we have Http and websocket protocols? And what with socketio??

gloomy root
#

Well SocketIO is just a wrapper for certain protocols from just HTTP sockets to Websockets

#

the general order is:

Websockets
    |
   HTTP
    | 
   TCP```
#

Socket IO is just built ontop of the HTP and Websocket systems to provider a easier wrapper for them

#

its not its own set of protocols or anything special like that

dreamy python
#

@gloomy root ok so actually socektio protocol contain this flow chart u showed?

gloomy root
#

what?

#

SocketIO is just a wrapper

#

Especially Python's SocketIO module

#

all it does is wrap existing modules for use

#

When you make a standard SocketIO server it defaults to the HTTP protocol which is built on top of the TCP protocol

#

If you make it create a Websocket server it would make a HTTP server that then Upgrades the connection to a Websocket providing the relevant headers are provided

dreamy python
#

@gloomy root so actually socketio isnt protocol? its just a lib?

gloomy root
#

@dreamy python yes its just a lib

dreamy python
gloomy root
#

On the Network its not its own protocol

#

It is its own system in terms of the event based system but Websockets and HTTP are their own protocol individually

#

Ig? you could call it its own protocol because used across networks with Js etc... but i dont think its entirely valid to call it that

dreamy python
#

@gloomy root ok but still what do u mean when ur saying "On the Network its not its own protocol" its protocol or not?
and can u confirm/correct me if im wrong about "so actually when im using socketio lib im executing the 3 protocols u said websocketos(OSI layer 7) and http and TCP which on(layer5??)??"

gloomy root
#

I would use the term executing 3 protocols

#

They're all built ontop of each others rather than 1 executing the other executing the other etc...

dreamy python
#

ok so what is located on the toppest? and what is the corrsponding layer to him?

gloomy root
#

TCP - Layer 4

HTTP - Layer 7

Websocket - Layer 7

SocketIO - Not a OSI Layer

dreamy python
#

ok now im starting to understand it thanks so actually socketio lib is gathering all those 3 protocoles together
so when there is relation between client to server
the server is sending req' to client ->Http protocol is initated to start the connection and after that the Websokcet is cont' to take the connec' open untill it being closed from server/client and transformation of data/connection is being executed with TCP protocol?
if im wrong please fix me ...thanks
and in conclusion its wrong to say socketio is protocol the right term is lib?(cause on the link i send u they saidWhat is Socket.IO?¶ Socket.IO is a transport protocol that enables real-time bidirectional event-based communication between clients (typically, though not always, web browsers) and a server. The official implementations of the client and server components are written in JavaScript. This package provides Python implementations of both, each with standard and asyncio variants.)

gloomy root
#

technically? yes

#

but SocketIO isnt always websockets

#

its most common system is just built on HTTP alone not using Websockets

dreamy python
#

can u please explain the flow of things between the protocols??(like whats happening behined the scens of establishing connection between client and server

gloomy root
#

Its mostly just abstractions between layers

dreamy python
#

i got this pic' which im trying to explain according to her but still little bit thougher

gloomy root
#

In the Same way a High level programming language is a higher level abstraction of a low level language e.g Assembly

#

In that example

#

It seems the Client will need to send a GET HTTP requests

#

Which is then put through a Upgrade system built into HTTP via Headers creating a 3 way handshake

#

Thats basically how a Websocket works

dreamy python
#

@gloomy root ok but in the handshake which parameters are being settled? and also where we see on this example the TCP protocol?(only when sending data right?)

gloomy root
#

Everything is HTTP

#

I really would worry yourself with TCP

#

TCP is the Raw protocol that HTTP is a higher level abstraction of in reality

#

So everything HTTP/1.1 and HTTP/2 is TCP

#

technically everything HTTP/3 is UDP with TCP verification of packets.

#

HTTP/3 is a very new system tho which i wouldnt worry about

dreamy python
#

i know generaly TCP role is to ensure safer way to send data without loosing it this is wrong??(according to ur answer what is the role of HTTP protocol?)
ok according to what u said "in the handshake which parameters are being settled??"

gloomy root
#

HTTP is just a protocol built on top of TCP to make transfer easier across the w3

dreamy python
#

@gloomy root ok i see and about the handshake para'

#

im asking it cause ive been told that when im using socketio lib i cant know the rate/speed of data transfering right/wrong? (its being settled by the network)

gloomy root
#

you cant really do that for any lib

#

SocketIO regardless

#

It just depends on too many things

#

The server Network speed, The client network speed, how fast the server can write to the socket etc...

dreamy python
#

you cant really do that for any lib
@gloomy root i dont understand what i cant do for any lib ? i didnt understand on what ur talking about?
and what is being settled on the handshake (main things)

gloomy root
#

You cant know the rate/speed of data transfer

#

tho that question doesnt make much sense anyway

dreamy python
#

@gloomy root ok fine i asked that cause i know that on handshke process

#

both sides decides about rate/speed which they gonna talk
so because of that i asked about whats mainly happening /being decided on handshake??

gloomy root
#

well that depends on the protocol

dreamy python
#

@gloomy root ok so i guess in my case its related to http?if u can explain some of features/parameters which being settled..

dreamy python
#

@gloomy root ??

gloomy root
#

A HTTP upgrade is pretty much just sending a response back with a Upgrade header, checking the responding headers and then passing it off

dreamy python
#

@gloomy root ok so i guess in my case its related to http?if u can explain some of features/parameters which being settled..
@dreamy python
Can u please answer my questions straightforward cause i didnt understand ur answer

gloomy root
#

I mean i just did

#

The whole point of HTTP is to be simple

#

Its not a overly complicated system,

dreamy python
#

Ok but still u didnt give me simple straightforward answer about my questions

#

I mean to handshake

gloomy root
#

Idk how else you want me to describe the fact its just sending back another response with some diffrent headers

dreamy python
#

Features/parameters.. which mainly being settled...

gloomy root
#

There isnt any

dreamy python
#

Between client and server

gloomy root
#

Its just Headers

#

as described by the link above

dreamy python
#

So why its called handshake (http upgrade)?

gloomy root
#

Not really any main reason

#

its just adding a extra step between before communication

dreamy python
#

I know generally it should be settle some parameters beterrb both sides ...but according to what ut saying its not doiing it ..so actually what it does?(exceot of headers)

gloomy root
#

its litterally Just headers

#

its only purpose is switching protocols

#

E.g from HTTP to a Websocket connection

dreamy python
#

U mean like client sends request for moving to websocket from http, so first he sends request for http connection to server and server sends to client ack and then moving to websocket??

gloomy root
#

I mean i can only tell you what the link i sent above will tell you

#

Client: "Id like todo this and Upgrade our connection"
Server: "Okay upgrade you want to upgrade to xyz"
Client: "Yes okay heres the relevant details"
Conection upgraded

#

Obviously this is massively simplified

dreamy python
#

Ok u illustrated this very good and simple,cause i really got confused cause i read about http and thought it should act differently because of handshake...

azure aurora
#

Are there any clever python tools to test networks? Like we have tcpplay tool kit and tcpdump or wireshark for recording

strong prawn
#

Guys do you know where to start learning Python Networking? Some tips on YouTube tutorials and articles are welcome. Thanks for tips

restive blaze
#

networking what

dusk sparrow
#

Hello , I've been trying to setup kubernetes on my ubuntu 20.04 machine , but inspite of installing kind and kubectl ,and moving them to /usr/local/bin ,I'm unable to run kind create cluster , as it simply says ./kind: 1: Not: not found, github issues told to install kubectl but that doesnt fix the problem either , anyone has any insight into the issue?

#

another thing I noticed is that , running xxd on the kind binary just gave a single line of 00000000: 4e6f 7420 466f 756e 64 Not Found

#

Here's how I installed kind sh curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind

graceful night
#

Would anyone in this channel be able to tell me why I keep getting Ether / ARP who has ?? says ?? from this code ``` #!/usr/bin/env python3

import scapy.all as scapy

def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
print(arp_request_broadcast.summary())

scan("10.0.0.1/24")

copper trench
#

Hi everyone,
is anyone familiar with nOBEX ?

loud tulip
#
import socket
client_socket = socket.socket()
port = 5000
client_socket.connect(('127.0.0.1',port))
recv_msg = client_socket.recv(8192)
print (recv_msg)
send_msg = input("Enter your user name(prefix with #):")
send_msg = send_msg.encode()
client_socket.send(send_msg)
while True:
   recv_msg = client_socket.recv(8192)
   print (recv_msg)
   send_msg = input("Send your message in format [@user:message] ")
   send_msg = send_msg.encode()
   if send_msg == 'exit':
       break;
   else:
       client_socket.send(send_msg)
   client_socket.close()
#

What do u think is wrong here in this client

#

???

gloomy root
#

to much magic dust

#

you havent actually told us an error

#

the thing which stands out the most is the fact you:

a - close the socket on the first message
b - compare bytes to a string
c - 🤷‍♂️

ember ledge
#

I'm looking to write a simple networking server (for a machine to machine related project which will at most need to handle 100 concurrent connections) and was wondering if I should roll out my own server using sockets and threading or if I should just use asyncio.create_server instead

crystal estuary
#

Hi, how would I make a query to a graphQL endpoint via aiohttp ClientSession?

vernal surge
#

@crystal estuary use their documentation to craft the query, otherwise, it's pretty well the same as any other HTTP based API endpoint

#

@ember ledge define "networking server" ... what is it your app is doing? i'm not sure whether or not to suggest a web server library or web sockets, or 🤷 lol

gloomy root
#

Deadlocks + Network = A really bad time

#

6 Hours of debugging later, the network finally doesnt lock up on high loads

ember ledge
#

@vernal surge the server is going to have other clients connect to it and serve as a hub for other clients to send json like data structures to one another.

vernal surge
#

@gloomy root you are doing something very long if you are getting deadlocks lolol

#

@ember ledge A simple web server works just fine though ... fastapi would but quite alright

gloomy root
#

Go lang + RwLocks + Nested Maps with channels apparently = Big oof

vernal surge
#

rwlocks? not just builtin mutexes?

gloomy root
#

Well I could use mutexes but that would be inefficent

#

the system is 90% read over write

vernal surge
#

ah, gotcha

ember ledge
#

I want the clients to always be connected to the server so they can listen for specific data being sent by the server, I also thought that FastAPI was only meant to be used for HTTP related server networking

vernal surge
#

@ember ledge well... when passing json objects around, that process is typical not an instantanious thing. Your clients would request from the server "did anything come for me" and the server would deliver. But if you need something more realtime, yeah, websockets would probably work just fine. All of this being said, I have no idea what you are actually doing ... but it sounds like you already have you mind made up, so carry on.

#

what is it you are building @gloomy root ?

restive blaze
#

@ember ledge Use WebSockets if Server needs to signal to client in real time

gloomy root
#

Specifically working on some sharding system between the workers to test if it has any different on load balancing / efficiency or not

ionic bluff
#

Hello!

#

How would you get that part?

narrow oak
#

think this might be suited in one of the help channels, but if the link only has one / then you could do: link.split('/')[-1] (might even work with multiple /s). Or use regex.

gloomy root
#

i mean if you know its always gonna be https://www.google.com/ you can just use strip

hexed epoch
#

you can also use urllib.parse

In [1]: from urllib.parse import urlparse

In [2]: d=urlparse('https://google.com/path')

In [3]: d
Out[3]: ParseResult(scheme='https', netloc='google.com', path='/path', params='', query='', fragment='')

In [4]: d.path
Out[4]: '/path'
#

it's probably more robust than anything we'd suggest here, but it does require a fully qualified URL (which means it needs the protocol at the beginning)

kindred ferry
#

Guys do you know how to take api from mobile app

undone gust
#

Guys do you know how to take api from mobile app
if it's public, google it, if it's not, you won't be able to, and besides i'm pretty sure it'd be illegal

#

basically, google it. @kindred ferry

kindred ferry
#

I have but still dont know

half urchin
#

how to find out all the information about the network?(I mean, which ones are closed, which ones are open, etc.)local network
like all about router, provider

thorn stratus
#

What specifically do you want to know

#

are you talking about like network scanning?

wide sail
#

I would recommend not helping people pentest networks @thorn stratus

#

Kinda like showing random people on the internet how to break into appartments

thorn stratus
#

network scanning is not illegal or even unethical

#

and has legitimate purposes

wide sail
#

Yes, but can easily be abused. It is not illegal breaking down a door, if it is your own door. But with that knowledge you can easily break down other people's doors as well.

wanton egret
#

Prepare yourself for a stupid question; can you just link between pages like you would if you where viewing the page in a browser (with flask)
If not are there any suggestions for something like flask but with that ability?

gloomy root
#

@wanton egret wdym

wanton egret
#

like in normal html you can just use href="test.html" but in all the flask examples I've seen you need href="{{ url_for('test') }}"

#

is the href="{{ url_for('test') }}" needed?

#

i already have the webpage and it uses href="test.html" i don't want to change the pages because that would take 2 long

#

i also dont want to add @app.route() for all of them

shy pebble
#

If you want to use templates, you need a route. If you just want a static html page which talks to a flask API, you could just have static files.

simple flax
#

I'm creating a desktop application and one of the features is to send a friend request. Now lets say two clients are open and client A sends a friend request to client B, Whats the best way to show on client B that he got a request. Do I create a socket on client B which constantly pings the server for friend requests or use websockets?

#

First time client B opens it's no problem since it will send an api request which checks if there are any friend request.

#

I'm thinking of an event driven solution but not sure how to accomplish this

shy pebble
#

There is also eventstream, but of you end up wanting more updates, websockets are probably a good choice

olive flower
#

Is it better to ask here or in async about something Twisted related?

tall olive
#

i imagine it depends on the question.

olive flower
#

My question would be that: Is there a good solution to create a task.LoopingCall and change/modify the time inside the passed function. or is that not possible?

#

like starting the call with something like

#
loop = task.LoopingCall(myfunc)
loop.start(30.0)
#

first run will be after 30 seconds, and the next run for example 45.0 secs

#

can I just accomplish that with the deferred it returns?

shy pebble
#

The most common way to do that in general is just to "recursively" schedule yourself once you are done with the bigger number

olive flower
#

I see. I guess LoopingCall isnt the way to go then.

shy pebble
#

Probably not, unless twisted has task local variables or sth

olive flower
#

I guess I'll just go with callLater

#

Thanks for your help though

#

A bit of a hacky solution would be to use LoopingCall but inside myfunc I could use a random sleep

#

but that sounds ugly I think

turbid drift
#

I'm using the Python sockets library. I know how to send a signal from the server to the client, but the client is just waiting for the server to respond, because they sent a request first. How do I make it so that the server can send a signal whenever it wants, without the client sending a request for this signal, and create a function that will handle the signal when it's received on the client side?

Example:

Server:

conn.send("Execute Order 66".encode(FORMAT))

Client:

client.recv(2048).decode(FORMAT) #calls a function with an argument that is the message received

def messageReceived(msg):
  if msg == "Execute Order 66":
    killJedi()
#

(I don't want the client constantly sending a request to the server every second checking if there's any data it should know)

thorn stratus
#

Recv will block until it gets the data or times out

#

So just put that on a loop

ember ledge
#

How do I get the program to check if there is wifi on the device

vernal surge
#

@ember ledge specifically wifi? Or just connectivity?

ember ledge
#

like if theres connaction

vernal surge
#

@ember ledge you could just do a simple http GET to Google or someone. If that errors, then you know you don't have any connectivity lol

ember ledge
#

ig

vernal surge
#

Otherwise, you would need to interface with the OS network provider (and on Linux, there are a number of those possible lol) to query if a connection is present.

ember ledge
#

hmm

vernal surge
#

Or if you only care about local connectivity, you could just ping the router

ember ledge
#

and how would I have it route so if its run on another pc

#

then It can check

vernal surge
#

Pc on the same network or not?

ember ledge
#

different

vernal surge
#

What are you doing exactly? If you are building a client server thing, then just have an endpoint on your server that the client can touch to verify connectivity.

ember ledge
#

A program that pings to a website for an api but like it had more than one

#

So I was thinking I can make a function

#

that is called in the function for the api

vernal surge
#

I'm having a hard time understanding lol

#

Why do you need an extra function?

ember ledge
#

make it easier to call when I need it

vernal surge
#

The call to the API is either going to fail or not

ember ledge
#

yeah thats tru

vernal surge
#

Just wrap in a try/except and, if it excepts, you can write some retry logic or not, whatever lol

ember ledge
#

yeah Ill just do that then

vernal surge
#

I tend to write retries with backoffs, first retry in 10 seconds, then 30, then 60 and bail if the third retry fails

ember ledge
#

I might just have it

#

if theres an error then like print unable to connect

vernal surge
#

Yeah, that's pretty typical

ember ledge
#

yeah thx for the help

vernal surge
#

Np

#

It's really hard not to over engineer, but try not to do extra work if you don't have to :)

iron shell
#

Has anyone ever gotten ssl working in python

#

?

vernal surge
#

Define ssl

#

But TLS, yes lol

iron shell
#

Trying to make an https socket

#

Keep getting bad file descriptor error

vernal surge
#

E2EE?

iron shell
#

idk what that means

vernal surge
#

End to end encryption?

iron shell
#

Yeh

#

I've made a .pem file and everything

vernal surge
#

Ok, are you doing sync or async cryptography

iron shell
#

I've gotten my http proxy working but I need it to also have https capabilities or ill keep getting permanent move address errors

#

I dont know I've just been winging it for about 2 hours

vernal surge
#

You are trying to intercept https?

iron shell
#

Im trying to make an https server and client

vernal surge
#

Remind me why you are doing this, because we are getting dangerously close to MITM territory lol

restive blaze
#

But Why?

iron shell
#

I just wanted to make a proxy

restive blaze
#

errr, ok

iron shell
#

To say I could

vernal surge
#

Ok, so yeah, a mitm

iron shell
#

And to learn sockets

#

Whats a mitm?

restive blaze
#

👍

vernal surge
#

Man in the middle

iron shell
#

I'm not trying to eaves drop i just started it so I wanna finish it fully working

vernal surge
#

Https interception is a lot of work

#

Big name proxies have a hard time with it even

iron shell
#

Damn

#

U got any good sources I could read?

vernal surge
#

General flow is this:

  1. Client wants to go to a secure site via proxy
  2. Proxy sees the request, and generates a self (or local CA) signed certificate for the requested site.
  3. Proxy makes the request on behalf of the client
  4. Secure server responds like normal, but to the proxy, not the client
  5. Proxy reads and rewrites that response with the proxy cert
  6. Proxy responds to the client on behalf of the secure server
#

And mind you, this has to happen in both directions, in real time

#

And if you don't have a local CA that the client trusts, it won't work anymore because browsers all but block SSCs

iron shell
#

Ah ok that makes sense

#

Google web pages made this seem alot more daunting

vernal surge
#

It is daunting, I way over simplified it lol

#

It's not impossible, but it's hard

iron shell
#

Thats how Feynman teaches and you just made understanding this alot easier for me

vernal surge
#

Glad I could help lol

iron shell
#

Thanks dude im gonna go back to figuring it out

vernal surge
#

Doing this is like living a lie, the hardest part is keeping track of the lies (sessions/certs/keys)

mental summit
#

How can i check if my router supports IPv6??

torn sail
#

If it supports it, it'll have assigned you one

#

If you're on windows, open a command prompt and type ipconfig /all, if you have a link local IPv6 address, your router supports it

ember ledge
#

hey

#

do anybody works with heroku?

#

it works normally at the start, later it got an r10 error

gloomy root
#

couldnt bind to port

modest pebble
#

My best guess is that you don't have an env var named $PORT, or you aren't making it being evaluated by the shell

#

The error message says that you want to bind to a port named literally $PORT, but it ports are only numbers, not words

cedar forum
ember ledge
#

client

import socket
import time
import os
import sys
import threading
import subprocess

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

HOST = socket.gethostname()
PORT = 8888


def connect():
    try:
        server.connect((HOST, PORT))
        messages()
    except (ConnectionRefusedError, TimeoutError):
        print("reconnecting, please wait...")
        time.sleep(0.1)
        connect()
        
def send():
    while True:
        message = input(">>> ")
        server.send(message.encode())
        
def messages():
    while True:
        threading.Thread(target=send).start()

connect()

server

import socket
import threading
import time
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

host = socket.gethostname()
server.bind((host, 8888))
server.listen(30)

            
print("The server has been launched succesfully!")
while True:
    conn, addr = server.accept()
    print(str(addr[0]) + " has connected succesfully!")
    command = conn.recv(1024).decode()
    print(command)
#

in the server i receive one message

#

instead of tons

ionic bluff
#

Hello,
I am searching for a Handful of People which would be helping in a medium sized Project.
If you would be interessed in joining, DM me.
The current Project is kind of part of Networking.
Regards,
ErrorCauser

restive blaze
#

I love how diplomatic Cloudflare was being

#

So why did it take more than four hours to resolve? It took 4 hours to resolve because cost cutting

#

They are a very sophisticated network operator with a world class Network Operations Center (NOC) With all cuts I've seen in NOCs, cough bullshit cough their NOC assuming it wasn't outsourced to lowest possible bidder was likely staffed with Tier 1 people who couldn't resolve it and customers have ability to do flowspec changes because ISPs don't want to keep proper staff on hand to resolve this.

cedar forum
#

Hahahaha yeah I think they are trying to criticise while maintaining access to the network

#

customers doing flowspec changes sounds like a great idea /s, does that actually happen?

#

I think that other CloudFlare outage was amusing

#

Routing all traffic through Atlanta

#

and then the trending hashtag was that discord was down, not cloudflare, hahaha

restive blaze
#

Joe, we had ability to do that at last job. All the budget cuts mean we couldn’t get anyone with a brain on the phone so that was their solution

cedar forum
#

Sheesh

restive blaze
#

Just like Devs are QA isn’t DevOps! But CheapDev!

#

ISP is one of those there is limit to amount of business available so after that, only way to increase profits is cut expenses

#

And clouds have been hurting ISP business since big money is in datacenter transit and more companies are shutting down data centers

cedar forum
#

Yeah

restive blaze
#

What's year look like

#

so my point about decline

sinful pine
#

Do the robots.txt restrictions for web scraping (such as crawl delay), apply to the robots.txt file itself?

vernal stirrup
#

has anyone tried sending udp packets via netcat command in terminal? after opening a client, and sending something, it just exits

// client
nc -u localhost <port>

// server
nc -u -l <port>
restive blaze
#

kolx why would it not exit

#

plasma, generally not, robots.txt is considered open to web crawlers because it's for them

vernal stirrup
cedar forum
#

@vernal stirrup change the server command to nc -u -l localhost 8080

#

that worked for me just now locally on mac, stopped the client exit

spare ferry
#

hello, im new to socket programming in python and im trying to create a simple chat. the problem is that i dont know how to make it possible to run the listening loop while waiting for the user input at the same time. this is why i reached up to this point so far, and im looking for ways to fix it.

import socket

class User:

    def __init__(self, username):
        self.username = username

    def set_server(self, host, port, size, time, run=True):
        while run:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
            s.bind((host,port))
            s.listen(time)
            client, address = s.accept()
            data = client.recv(size)
            if data:
                message = '[' + address[0] + ' - ' + data.decode() # username comes in data example: user123]: some data
                print('{}'.format(message))
            s.close()

    def set_client(self, host, port, message):
        s = socket.socket(socket.AF_INET, socket.STREAM)
        s.connect((host,port))
        data = self.username.encode() + b']: ' + message.encode()
        try:
            s.sendall(data)
        except Exception as e:
            print('SOCKET ERROR:',e)
        finally:
            s.close()

#### TEST###########

if __name__ == '__main__':

    server_running = True

    username = input('Username~# ')
    user = User(username)
    host = input('Host~# ')
    port = int(input('Port~# '))

    message = input('['+username+']: ')
    user.set_server('', 37554, 512, 5, server_running)

    if message:
        server_running = False
        user.set_client(host,port,message)
        message = None
        server_running = True```
gloomy root
#

I would highly advise learning classes and general string formatting before jumping into socket ignore that, phone made it look like you were doing weird stuff

empty solstice
#

hello, im new to socket programming in python and im trying to create a simple chat. the problem is that i dont know how to make it possible to run the listening loop while waiting for the user input at the same time. this is why i reached up to this point so far, and im looking for ways to fix it.

import socket

class User:

    def __init__(self, username):
        self.username = username

    def set_server(self, host, port, size, time, run=True):
        while run:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
            s.bind((host,port))
            s.listen(time)
            client, address = s.accept()
            data = client.recv(size)
            if data:
                message = '[' + address[0] + ' - ' + data.decode() # username comes in data example: user123]: some data
                print('{}'.format(message))
            s.close()

    def set_client(self, host, port, message):
        s = socket.socket(socket.AF_INET, socket.STREAM)
        s.connect((host,port))
        data = self.username.encode() + b']: ' + message.encode()
        try:
            s.sendall(data)
        except Exception as e:
            print('SOCKET ERROR:',e)
        finally:
            s.close()

#### TEST###########

if __name__ == '__main__':

    server_running = True

    username = input('Username~# ')
    user = User(username)
    host = input('Host~# ')
    port = int(input('Port~# '))

    message = input('['+username+']: ')
    user.set_server('', 37554, 512, 5, server_running)

    if message:
        server_running = False
        user.set_client(host,port,message)
        message = None
        server_running = True```

@spare ferry bro TBH whatbyou are asking it can be just fixed with using threads

#

If you don't know what is that
You may search google cause explaining it here will be a headache

#

👍

spare ferry
#

I would highly advise learning classes and general string formatting before jumping into socket ignore that, phone made it look like you were doing weird stuff
@gloomy root damn u scared me for a sec

#

@spare ferry bro TBH whatbyou are asking it can be just fixed with using threads
@empty solstice alright ty

empty solstice
#

No problemo

gloomy root
#

Where asyncio would be better

spare ferry
#

ill try both and see

#

ty

#

so far threading seems fine

vernal surge
#

again, i feel the need to ask why peoples first jump into networking is raw sockets

spare ferry
#

my first was scapy actualyl

#

lol

#

and i dont see what bad in learning sockets first?

vernal surge
#

not that it's bad ... but there is usually a reason to go down to that level, generally it's not the thing you start with. I've been doing the software development thing for a bit and i can count on one hand the number of times I've actually had to use sockets in the past 5 years

#

for context ... 5 years is not the length of my career either lol

spare ferry
#

well, i want to get into pentesting, i guess it would be handy

vernal surge
#

Pentesting == running vuln scans and writing reports, it's not nearly as fun as it sounds 😄

#

very rarely does a company want you do develop APT level exploits against their network

#

and fwiw, I HAVE done professional pentesting, and python was not the language I used 😄

#

not to kill the dream here, but just being real

spare ferry
#

Pentesting == running vuln scans and writing reports, it's not nearly as fun as it sounds 😄
im fine with doing pentesting at home instead of playing video games, as a job im not worried rn because im about to get recurited in few months for about 3 years, probably something simple like network administrator or something
and fwiw, I HAVE done professional pentesting, and python was not the language I used 😄
what was the language you used then? i mean, a lot of pentesters in my country use python

vernal surge
#

It use to be Ruby (because metasploit), but I usually found myself writing C

#

now, I tend to use Rust/Go

#

C\C++\Rust\Go beacuse of the ability to compile and run anywhere

#

python needs an interpreter, and most of my targets didn't have one

spare ferry
#

what were you doing with C? like what kind of stuff
i learned some C basics, but i think that python is better in terms of pentesting networks compared to C, fix me if im wrong. were you doing other things with C tho?

vernal surge
#

and the pyinstallers of the world make life as a pentester a living hel

gloomy root
#

pyinstaller in the real world is a bit of a joke

spare ferry
#

really? why

#

i mean

#

what about py2exe

vernal surge
#

they wrap an interpreter in

gloomy root
#

A) Lack of Efficiency of storage
B) Lack of Speed
C) No active multi os support
D) Dependency hell
E) Can still require external deps be packaged with it

vernal surge
#

but re: "why C", python abstracts away too much of the low level stuff you need for certain exploits

#

I agree, it's not a great tool for doing network level stuff due to the verbosity

#

that is where I use Go now ... and Rust is now my low level tool

gloomy root
#

Rust is great because you get the safety of high level languages but equally are able to still do unsafe low level things

vernal surge
#

I'm working on a generic proxy for rust though, so I can stick to one language

gloomy root
#

Are you doing it with raw sockets or something like hyper?

vernal surge
#

raw, specifically, I'm targeting one particular ether card for a particular engagement, but when I get done, i'll probably use something a little higher level to be more consistent with the ecosystem

gloomy root
#

Async or going with the std lib?

vernal surge
#

stdlib

gloomy root
#

fairs

vernal surge
#

trying to not use any deps right now

gloomy root
#

the only thing i have against the std lib with networking is some hard coded things that have been left out of docs and havent been updated

#

like SO_REUSEADDR only being enabled on Linux even tho Windows now supports it

vernal surge
#

sounds like a good pull request lol

gloomy root
#

and you have no way of manually overriding or controlling it which is a pain

#

i was planning todo either a issue or pr for the docs but going back to school in 2 days so gotta deal with that

vernal surge
#

ahh, the good ole' days lol

gloomy root
#

Really just hoping i can drop maths and go with a Btec course instead

vernal surge
#

i've been considering going back for a degree, probably CS, because algo shit is dumb and i need to learn it lol

gloomy root
#

the lockdown period has pretty much nuked my chances of passing lol

vernal surge
#

yeah, the lockdown period, i thought it wasn't going to affect me as much as it has (considering that I was already 100% remote before the pandemic), but surprisingly, i've seen a decrease in my ability to concentrate

gloomy root
#

Its a nightmare for school because there is no escape from the work

#

before you'd go to school get back home and you could relax a bit

#

but just massive stress now

restive blaze
#

I've seen python used for websploits

vernal surge
#

yeah, not that i've not used python, but it's rarely the best tool in my use case

mild coral
#

Hey, I'm trying to send a post request to a webhook, but have some errors using this code:

def __init__(self,hook):
        self.hook = "https://discordapp.com/api/webhooks/"+hook
        self.template = '{"content":"$content"}'
        self.type = {'Content-Type':'application/json'}
def Send(self,messages):
        count = 0
        for message in messages:
            count += 1
            content = self.template.replace("$content",message)
            content = content.encode('utf-8')
            result = requests.post(self.hook, data=content, headers=self.type)
            print("Encoding is: " + str(result.encoding))
            try:
                result.raise_for_status()
            except requests.exceptions.HTTPError as err:
                print(err)
            else:
                print("Message sent successfully, code {}.".format(result.status_code))
            if len(messages) > count : time.sleep(1.5)

2 messages should be sent, but I get an error with the second one:

Encoding is: utf-8
Message sent successfully, code 204.
Encoding is: None
400 Client Error: Bad Request for url: SOME URL
gloomy root
#

Can't do post requests on webhooks

#

The initial request must be a Get request that is then upgraded to the ws protocol

#

Ignore all of the above I can't read on mobiles it seems

#

Is this a discord webhooks by any chance

mild coral
#

Yes

#

I edited the message above to include the header too

#

I do have some unicode characters in the messages too

thorny breach
#

I have ssh script using paramiko, on my mac it run without issue when i try to run on windows its gives socket error.
and i am using multiple commands.

for ipp in ips:
    ip = ipp.strip()
    print(ip)
    port = 22
    username = 'admin'
    # password='AeGEBUx66m_1ND'
    cmd = 'interface wireless set scan-list=5150-5250,5725-5875  number=wlan1-gateway'
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(ip, port, username, timeout=5, password='broot')
        ssh.exec_command(cmd)
        stdin, stdout, stderr = ssh.exec_command(
            'interface wireless scan  number=wlan1-gateway background=yes duration=15')
        ftoutlines = stdout.readlines()
        resp = ''.join(ftoutlines)
        str1 = 'Online'
        status = 'Done'
        ssh.close()
    except socket.error:
        str1 = str("Offline")
        # df.loc[ip] = [ip, str1, "Offline"]
        status = 'Offline'
        Frequency = 'Offline'
    except AuthenticationException:
        try:
            ssh.connect(ip, port, username, password='bsroot')
            ssh.exec_command(cmd)
            stdin, stdout, stderr = ssh.exec_command(
                'interface wireless scan  number=wlan1-gateway background=yes duration=15')
            ftoutlines = stdout.readlines()
            resp = ''.join(ftoutlines)
            # outlines.reverse()
            # print(resp)

            str1 = 'Online'
            status = 'Done'
            ssh.close()
#

Error on windows -

(10054)
mild coral
#

@gloomy root I solved the issue. When converting to utf-8, it converted some tabs as the \t character which seems to have been the error

thorny breach
#

I have ssh script using paramiko, on my mac it run without issue when i try to run on windows its gives socket error.
and i am using multiple commands.

for ipp in ips:
    ip = ipp.strip()
    print(ip)
    port = 22
    username = 'admin'
    # password='AeGEBUx66m_1ND'
    cmd = 'interface wireless set scan-list=5150-5250,5725-5875  number=wlan1-gateway'
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(ip, port, username, timeout=5, password='broot')
        ssh.exec_command(cmd)
        stdin, stdout, stderr = ssh.exec_command(
            'interface wireless scan  number=wlan1-gateway background=yes duration=15')
        ftoutlines = stdout.readlines()
        resp = ''.join(ftoutlines)
        str1 = 'Online'
        status = 'Done'
        ssh.close()
    except socket.error:
        str1 = str("Offline")
        # df.loc[ip] = [ip, str1, "Offline"]
        status = 'Offline'
        Frequency = 'Offline'
    except AuthenticationException:
        try:
            ssh.connect(ip, port, username, password='bsroot')
            ssh.exec_command(cmd)
            stdin, stdout, stderr = ssh.exec_command(
                'interface wireless scan  number=wlan1-gateway background=yes duration=15')
            ftoutlines = stdout.readlines()
            resp = ''.join(ftoutlines)
            # outlines.reverse()
            # print(resp)

            str1 = 'Online'
            status = 'Done'
            ssh.close()

@thorny breachThis is fixed, Thanks

dusk sparrow
#

Hello , I've been trying to use kubernetes to manage my containerized applications , but while hosting a service, when I try to port forward , it always errors out saying unable to forward port because pod is not running. Current status=Pending. I've tried looking into github issues regarding the error , and all they suggest is to look into docker logs, but I dont see any errors in the logs too. Can someone give me an insight into this?

vernal surge
#

@dusk sparrow how/where are you running k8s?

dusk sparrow
#

Im using k8s on ubuntu 18.04 , basically I was trying out google's kctf framework

vernal surge
#

Ok, still didn't answer my question :D

dusk sparrow
#

I mean , I dont want u to spend ur time in going through that , but Im kind of stuck with the port forwarding 😅

#

Ok, still didn't answer my question :D
oh sorry , let me be more precise

#

I was using k8s on my ubuntu 18.04 virtual machine

vernal surge
#

Obviously, you went the k8s route, but which way

dusk sparrow
#

should I also paste the steps I used ?

vernal surge
#

Sure

dusk sparrow
#

first , I did , kind create cluster

vernal surge
#

My first guess is that your VM is under resourced and won't run KIND well

dusk sparrow
#

ok , so low on RAM u mean?

vernal surge
#

I assume the VM is because you are on windows?

dusk sparrow
#

well actually , I had trouble getting kind run on my local ubuntu 20.04 ,so I switched to vm

vernal surge
#

Yuck lol

dusk sparrow
#

My first guess is that your VM is under resourced and won't run KIND well
well , one of my peers also encountered the same issue on their local machine

vernal surge
#

Why not just use minikube or microk8s

dusk sparrow
#

oh okay

vernal surge
#

In Ubuntu, use microk8s

dusk sparrow
#

how much resource is required for running k8s smoothly without any resource related issues?

vernal surge
#

Uh, that's a hard question because it depends on your workload

dusk sparrow
#

lets say I have 4 very basic applications which have to be accessed with just a simple netcat

#

is k8s resource intensive?

vernal surge
#

Ok, it depends what your manifests look like

dusk sparrow
#

yah

vernal surge
#

It doesn't have to be super resource intensive, but it can get that way in a hurry if you don't use limits

dusk sparrow
#

okay , I see

vernal surge
#

But generally speaking, for a testing, single node cluster, I wouldn't try to run anything of note without 8GB of RAM and at least at minimum an i7 (or equivalent)

#

You can get by with less, but you will be OOMing pods all over the place

dusk sparrow
#

woahh

#

that much???

vernal surge
#

Lol that isn't that much

#

My production nodes run no less than 64GB

dusk sparrow
#

8 gb ram is kind of okayish , but i7 is luxury for sure

#

we plan to deploy kubernetes on a bare metal vm and host applications all year long

#

do u suggest to have vm scaled to have 8 gb ram and i7 core?

vernal surge
#

Bare metal kubernetes isn't exactly easy FWIW

#

Storage is the real problem

dusk sparrow
#

storage as in ?

vernal surge
#

Pod/container storage

dusk sparrow
#

Bare metal kubernetes isn't exactly easy FWIW
yah right

vernal surge
#

I assume you want to be able to give the pods a place to store data xD

dusk sparrow
#

the thing is , we already have creds for a cloud service called Hetzner , so we plan to deploy k8s on the instance so that it can monitor all services without having to use another service like aws to do that

vernal surge
#

What instance, thought you said it was bare metal

dusk sparrow
#

yah sorry , bare metal itself

#

I meant bare metal cloud

vernal surge
#

Ah, ok, that makes more sense

#

So hetzner is the provider? Or aws?

dusk sparrow
#

sorry for not being clear

#

yes hetzner

vernal surge
#

Ok, do they not offer a hosted k8s?

#

I only ask because most do

dusk sparrow
#

well , I dont think so , we plan to deploy k8s there

vernal surge
#

Doesn't look like it.

#

But ok, I'm started to piece together your needs lol