#networks

1 messages ยท Page 46 of 1

elder cobalt
#

I guess it might be because of this line

#

so I decided to load up a server with AI where each AI has a session ID + 2 real clients which are controlled from me

#

and when I put my session id which is 18 and not the AI ones

#

its following one of the AI's instead of me

#

it's following session ID 25

cloud spruce
#

can you add this print statement just (other lines are just for context) before the w.send(packet) of the first if block:

                packet.payload = bytes(data)
                print(f"target pos(x: {to_float(X_pos)}, y: {to_float(Y_pos)}, z: {to_float(Z_pos)}), rot (x: {to_float(X_rot)}, y: {to_float(Y_rot)}, z: {to_float(Z_rot)})")
            w.send(packet)
```and this `print` statement almost at the end of the `elif` block like this:
```python
            packet.payload = bytes(data)
            print(f"    my pos(x: {to_float(X_pos) + X_rel_pos}, y: {to_float(Y_pos)}, z: {to_float(Z_pos) + Z_rel_pos}), rot (x: {to_float(X_rot) + math.pi}, y: {to_float(Y_rot)}, z: {to_float(Z_rot)})")
            w.send(packet)
elder cobalt
#

yeah

#

its definitely following the wrong person

#

๐Ÿ’€

#

coz my coords are this

cloud spruce
#

let me check the session_id conversion code, haven't really read it, just copied it

elder cobalt
#

if I do understand this logic properly

#

data[1:2] will be comparing it with char of 18

cloud spruce
#

are you sure the session id is at [1]?

elder cobalt
#

yeah

#

when im using my old code

#

its working

cloud spruce
#

ok, so that is the position of right car then?

#

i think i know what it is... hold on

#

no, it wasn't what i first though

elder cobalt
cloud spruce
elder cobalt
#

hmm looks like even using my statement in yours doesnt work

cloud spruce
#

try with the one i sent just now

#

i hope i have not forgotten a fix that you have implemented in between, but i think i got them all

elder cobalt
#

๐Ÿ‘

cloud spruce
#

rewriting packets can be hard when i can't experiment with it my self ๐Ÿ˜†

elder cobalt
#

yeah I get you, it's a huge guess work since you can't really know what type of packets come across or go lol

#

also

elder cobalt
cloud spruce
elder cobalt
#

from

#

works

#

properly

#

and even captures the right car

#

just edited this in

#

btw was this supposed to be Z_rot or X_rot?

#

when I do relative_distance=5

#

when its relative_distance=0

#

relative_distance=3

cloud spruce
elder cobalt
#

Not sure, Z pos is basically

#

The car position in a XYZ Cartesian graph

#

If I recollect these are the only packets which are received by the client from server

cloud spruce
#

this should only be some basic trigonometry to position your car relative to the target car
we solve a right triangle (where the angle of C is 90 degrees) for the "adjacent side" (b) and the "opposite side" (a)
using relative_distance, which is really the length of the "hypotenuse" (c, the longest side) and "theta" (angle of A) but in radians instead of degrees and of us i think that is Z_rot

elder cobalt
#

Increasing it doesn't seem like to increase the distance between them but instead be positioned to the left of the car

cloud spruce
#

yeah, that should just copy the other car, but then we have a 180 degree rotation in there too

elder cobalt
#

hmm so you think rotation is messing it up?

elder cobalt
#

dont you think?

cloud spruce
#

i might have messed up the order of the sin and cos calculations in the function for the X and Z, just try this

def relative_position_2d(distance: float, rad_angle: float) -> tuple[float, float]:
    return distance * math.sin(rad_angle), distance * math.cos(rad_angle)
    #return distance * math.cos(rad_angle), distance * math.sin(rad_angle)
```the old return value is just commented out so that we can restore it easily if this messes things up even more
elder cobalt
#

when my X velocity is negative my world position becomes negative as well

#

when X velocity is positive my world position becomes positive as well

#

problem starts when X velocity is at 0 lol

#

not really 0 but yeah

cloud spruce
#

oh, the velocity is probably just like what you would get with a 3D gyroscope in a phone or other device that has them

elder cobalt
cloud spruce
#

then it's not correct, i need to revisit the calculation again, it should be find at 5, it's something else that's up with the positioning

#

what happens if you turn the target car like 90 degrees to one or the other side?

cloud spruce
#

with 5 that should look better

elder cobalt
elder cobalt
elder cobalt
#

eh cant

cloud spruce
cloud spruce
#

if it is it would look like the middle of the car is centered on the driver and not the middle of the car

elder cobalt
cloud spruce
#

okay, then that theory is out the window

elder cobalt
#

as well as for the abarth its left

elder cobalt
cloud spruce
elder cobalt
#

not sure

#

well lets say if its at the centre of the car

cloud spruce
#

maybe, then it will be hard to adjust for that without knowing the drivers position in relation to the car body for both the target car and your car

elder cobalt
#

if I were to increase X and Z by + 1 it should move + 1 in front of XZ direction right?

cloud spruce
#

i hope it's the center of the car, then it's no problem

#

i think it will move in relation to coordinates of the world map

elder cobalt
#

let me check up real quick with someone who might know the game's physics

cloud spruce
#

if you substitute X_rel_pos and Z_rel_pos with 5 in the calculation where you assign the value to data, like:

            data[6:10] = from_float(to_float(X_pos) + 5)
            #data[6:10] = from_float(to_float(X_pos) + X_rel_pos)
            data[10:14] = Y_pos
            data[14:18] = from_float(to_float(Z_pos) + 5)
            #data[14:18] = from_float(to_float(Z_pos) + Z_rel_pos)
```where the old calculations are commented out
#

your car will probably just be stuck on one side on the diagonal according to the map orientation and move with the target but not correctly when the target rotates
it will be like a static offset relative to the cars position but not take into account the direction of the car (other then our rotation) for positioning, that will be stuck with the world map

#

this is just to debug things

elder cobalt
elder cobalt
cloud spruce
#

and the distance will be more then 5 since it's on the diagonal, it will be around 7.07107 for distance

elder cobalt
#

@cloud spruce okay if I exclude the center of the car and maybe it's centered around the driver is there anyway to like mirror?

#

That way I always stay in front of the driver even if I turn or something?

cloud spruce
#

it you are okay with putting your drivers position right in front of the targets driver position we don't have such a big problem
it will just look a little bit weird since the car bodies will not align

elder cobalt
#

But yeah for now I'm fine with it

elder cobalt
#

eh guess I'm done for today

cloud spruce
#

i'm trying to mock things over here, but it's hard without any example data

cloud spruce
elder cobalt
#

gotta hit the bed

#

๐Ÿ˜ญ

#

but atleast found out what's possible and what's not

cloud spruce
elder cobalt
#

maybe once I wake up tomorrow if I have some time left I could look into the game's memory to find if it even loads up other car's heading

#

surely a client should know where the other car is facing if isn't sending packets maybe it's doing it within game itself but that'd take alot of years

#

luckily I have a debug file but I'm so bad at reverse engineering got to see what I can do

cloud spruce
#

guess i'll be seeing you here tomorrow, until then ๐Ÿ‘‹

elder cobalt
#

@cloud spruce iirc the game has some sort of prediction system filled in place as well so gonna try fiddling with velocity while my xyz pos are the same

elder cobalt
#

@cloud spruce asked a friend of mine he replies

cloud spruce
# elder cobalt <@936769916072259654> asked a friend of mine he replies

yeah, that's kind of what it though too, velocity shouldn't have anything to do with it other then that we move with the other car
that is, we should just copy all the velocity values from the target to our own car without any manipulation, i think the velocity is in relation to the map (just like position) and not in relation to the rotation of the car

elder cobalt
#

Where I asked again how to get hisfwd and he replied you get it based on the rotation

#

I've checked on the internet many say you normalize the Z rotation which finally made sense when you added in Z_rot but I didn't get this calculation

elder cobalt
#

@cloud spruce any idea if we can use math function to normalize Z rotation between -1 or +1?

#

wait it's already being done

#

but it looks like it's only like adding + 5 to the current position

#

when I use

def relative_position_2d(distance: float, rad_angle: float) -> tuple[float, float]:
    #return distance * math.sin(rad_angle), distance * math.cos(rad_angle)
    return distance * math.cos(rad_angle), distance * math.cos(rad_angle)
cloud spruce
#
    return distance * math.cos(rad_angle), distance * math.cos(rad_angle)
```is wrong, it should be:
```python
    return distance * math.cos(rad_angle), distance * math.sin(rad_angle)
elder cobalt
# cloud spruce ```python return distance * math.cos(rad_angle), distance * math.cos(rad_ang...

when I corrected the statement output shows

    my pos(x: 653.6578938854869, y: 89.28119659423828, z: 1410.950487438022), rot (x: 4.261828215914317, y: 0.023133646696805954, z: 0.06406708806753159)
target pos(x: 648.6681518554688, y: 89.28119659423828, z: 1410.63037109375), rot (x: 1.1201612949371338, y: 0.023069046437740326, z: 0.06374324858188629)
    my pos(x: 653.6579972901552, y: 89.28119659423828, z: 1410.9488715457721), rot (x: 4.261753948526927, y: 0.023069046437740326, z: 0.06374324858188629)
target pos(x: 648.6681518554688, y: 89.28119659423828, z: 1410.63037109375), rot (x: 1.1201030015945435, y: 0.02300095371901989, z: 0.06352806091308594)
    my pos(x: 653.6580657119953, y: 89.28119659423828, z: 1410.9477977851993), rot (x: 4.261695655184337, y: 0.02300095371901989, z: 0.06352806091308594)
target pos(x: 648.6681518554688, y: 89.28118896484375, z: 1410.63037109375), rot (x: 1.119991421699524, y: 0.022939220070838928, z: 0.06317082047462463)
    my pos(x: 653.6581787912351, y: 89.28118896484375, z: 1410.9460151659682), rot (x: 4.261584075289317, y: 0.022939220070838928, z: 0.06317082047462463)
target pos(x: 648.6681518554688, y: 89.28118896484375, z: 1410.63037109375), rot (x: 1.1199955940246582, y: 0.02289349026978016, z: 0.06316276639699936)
    my pos(x: 653.6581813332951, y: 89.28118896484375, z: 1410.9459749758937), rot (x: 4.261588247614451, y: 0.02289349026978016, z: 0.06316276639699936)
target pos(x: 648.6681518554688, y: 89.28118896484375, z: 1410.63037109375), rot (x: 1.1200497150421143, y: 0.022851286455988884, z: 0.06337600946426392)
    my pos(x: 653.6581139195009, y: 89.28118896484375, z: 1410.9470390579015), rot (x: 4.261642368631907, y: 0.022851286455988884, z: 0.06337600946426392)```
#

yikes

#

there a bit readable

#

target pos is at 648, but because of the way its facing it should be at 648-5 which is 653 but instead it's at 648+5

#

and Z position is not really changing as well, it should be 1410+5 = 1415 from the way its facing

cloud spruce
cloud spruce
#

could you also update the two print statements to this:

print(f"target pos(x: {to_float(X_pos):>12.3f}, y: {to_float(Y_pos):>12.3f}, z: {to_float(Z_pos):>12.3f}), rot (x: {to_float(X_rot):>12.3f}, y: {to_float(Y_rot):>12.3f}, z: {to_float(Z_rot):>12.3f})")
```and for the last one:
```python
print(f"    my pos(x: {to_float(X_pos) + X_rel_pos:>12.3f}, y: {to_float(Y_pos):>12.3f}, z: {to_float(Z_pos) + Z_rel_pos:>12.3f}), rot (x: {to_float(X_rot) + math.pi:>12.3f}, y: {to_float(Y_rot):>12.3f}, z: {to_float(Z_rot):>12.3f}), rel_pos(x: {X_rel_pos:>12.3f}, z: {Z_rel_pos:>12.3f})")
```it should make the output even more readable independent of the position on the map (edit: i shortened the name of `relative_pos` to `rel_pos` in the last snippet)
elder cobalt
#

for the second print statement

#

the first works fine

cloud spruce
#

ah, i forgot about one thing

#

there, i edited the last one now, the X_rel_pos and Z_rel_pos are already floats and don't need to be wrapped in to_float()

elder cobalt
#

took 3 snips

#

from start, in middle and end @cloud spruce

cloud spruce
elder cobalt
cloud spruce
elder cobalt
#

After that I started rotating in a circle

cloud spruce
#

i see it in the numbers now

#

we are using the angle from the wrong rotational axis, change:

X_rel_pos, Z_rel_pos = relative_position_2d(relative_distnace, to_float(Z_rot))
```to:
```python
X_rel_pos, Z_rel_pos = relative_position_2d(relative_distnace, to_float(X_rot))
#

we are turning around the X axis to change the heading of the car, not the Z axis

#

that's also the variable that we flip 180 degrees or 1 pi in radians to reverse the car relative to the target

#

@elder cobalt how is it working now?

elder cobalt
#

Loading the game up, took a short break but will get back to you in a bit ๐Ÿ‘

elder cobalt
#

So for the sake of simplicity let's keep relative distance at 1 so it'll be cos(3.14159) when my cars at 180 degrees which is 0.99849715 and then add that to my car B position?

cloud spruce
#

i think you will see exactly how behaves with the debug print statements on the console as you turn the target car around

elder cobalt
#

car's facing like this

cloud spruce
cloud spruce
elder cobalt
cloud spruce
elder cobalt
cloud spruce
# elder cobalt

and if you take a picture of the cars in relation to each other, how does it look?
i'm wondering if you ended up in front or behind the other car (depending on the world coordinate system in the game)

elder cobalt
cloud spruce
elder cobalt
#

sure

cloud spruce
# elder cobalt sure

after you went to sleep i found out why data[1:2] works and not data[1], it's because we are working with bytearrays, if you access just one element python returns that elements decimal value instead of the byte but when using slices it returns a new bytearray but holding just one byte in this case ๐Ÿคฆ

#

so, you will need to use slices everywhere when working with the bytearrays, so that needs correcting again as i had missed this detail with bytearrays when i edited the code

elder cobalt
#

hmm so it looks like when I move in a diagonal (I assume this because both my X and Z coordinates from world position are either both decreasing or increasing when I move) my X rotation is positive but my X and Z position coordinates are negative(or decreasing as I move)

cloud spruce
elder cobalt
#

current world position

#

this is of the red bmw

elder cobalt
# elder cobalt

now if I were to move to the coordinates of the teleported car

cloud spruce
#

they match the console output as well?

#

is the red car the teleported car or the target car?
i'm guessing it's the teleported car that is red, right?

elder cobalt
cloud spruce
elder cobalt
#

also yeah they do match the world position

cloud spruce
# elder cobalt also yeah they do match the world position

if you were to turn off your script and position the orange car approximately where you would expect it to be in relation to the red car without moving the red car from where it is right now and then give me the world coordinates and rotation of both cars i think i can work out what's wrong with the calculation for the relative positioning

elder cobalt
cloud spruce
elder cobalt
#

position and XZ rotation of the current red car bmw

cloud spruce
elder cobalt
cloud spruce
elder cobalt
#

orange teleported car

cloud spruce
elder cobalt
elder cobalt
#

only for rotation I enabled a separate script which just reads my rotation thats it

#

not manipulating it

elder cobalt
cloud spruce
cloud spruce
elder cobalt
#

my red car is in the pits and the pits location is the same if I teleport back to it

#

and I haven't even moved from it

cloud spruce
elder cobalt
#

of the red car

#

as it is right now

cloud spruce
cloud spruce
# elder cobalt as it is right now

is there any compass or heading in the game when driving the car or a picture of the map with the car on it in relation to the map or other indication of where north on the map would be in relation to the car?

elder cobalt
cloud spruce
elder cobalt
cloud spruce
elder cobalt
elder cobalt
#

uhh @cloud spruce have you heard about or tried kaitai?

cloud spruce
elder cobalt
#

I found out that I haven't decompiled the entire packet, it looks like modded server packets send bigger udp packets which contain information of other players in one single packet as a way to optimise

#

Thankfully it's repeatable I'm not sure tho how I could possibly do that with python but I've deconstructed the packets using kaitai into something more meaningful

cloud spruce
cloud spruce
elder cobalt
errant bayBOT
#

Hey @elder cobalt!

It looks like you tried to attach file type(s) that we do not allow (.zip). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a, .csv, .json.

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

elder cobalt
#

oops

#

should look somewhat like this(I've deleted some files but you could have a look at them)

#

client.ksy for client2server.bin
serverSTOCK.ksy for server2clientSTOCK.bin then,
serverMOD.ksy for either server2clientMOD.bin or need2decode blablabla

cloud spruce
honest drift
#

I'm sorry for making such a dumb question, but I couldn't find the answer I was looking for on the internet.
What is the use for network programming?
Why is it so important?
What would be an example irl that you'd need it?

cloud spruce
# honest drift I'm sorry for making such a dumb question, but I couldn't find the answer I was ...

network programming is what makes devices/computers able to talk to each other and exchange information
without it the internet (and the information age and the world as we know it today) wouldn't exist and you wouldn't be able to surf the web, search google, watch youtube, stream music, movies and series, read your e-mail, use social media and chat, make phone calls (other then as they did back in the day when you first talked to an operator who physically connected phone lines with wires for you to get to whom you wanted to talk to) or video calls
network programming enables all that, even if you have not written the code someone else has
you will need to learn it if you want to write your own code/program/application that exchanges information between devices

cloud spruce
elder cobalt
#

coz I just opened up a debugger for checking if I can find the direction of my car

cloud spruce
#

we have to subtract a rotation constant because first the X rotation is at a 90 degree angle, then we need to adjust a bit more because the center seem to be centered around the driver instead of the middle of the car body

cloud spruce
elder cobalt
cloud spruce
# elder cobalt

haha, the problem with not being able to run the code at all ๐Ÿ˜†

elder cobalt
#
X_rel_pos, Z_rel_pos = relative_position_2d(relative_distance, to_float(X_rot) - X_rot_fix)
cloud spruce
elder cobalt
#

hmm tried it out no luck looks like it's still retaining the same old position as before?

cloud spruce
elder cobalt
cloud spruce
# elder cobalt

aha, i think the rotation goes the other way around, try adding instead of subtracting

cloud spruce
#

and in that case, that probably goes for the subtraction in line 31, might need addition there instead

elder cobalt
#

line 31?

#

o X_rot_fix?

cloud spruce
#

try value 0 for X_rotation_adjustment

elder cobalt
#

yep

#

car's always in front it's a good sign

elder cobalt
cloud spruce
#

we might be a little bit off still, so you can adjust that angle in that variable to fine tune it (it's in degrees and you can use decimals and negative numbers too)

elder cobalt
#

I suppose you use relative_distance to define how far apart the car is?

elder cobalt
#

sorry

cloud spruce
#

that is to do the small adjustments to center the care head on, since the center of both cars seem to be the driver and not the car body

elder cobalt
#

perhaps rndpkt with the calculations you did won't it be possible to know where the car is facing?

cloud spruce
#

it's in degrees and you can use like -1.5 or 3.2 or what you need to fine tune the relative position

elder cobalt
#

like cardinal direction?

cloud spruce
# elder cobalt like cardinal direction?

probably, i think it's might just be something like math.degrees(to_float(X_rot) + math.radians(90)) to get the heading of the car in degrees, it depends on if rotation in the game is clockwise or counter-clockwise
if you want it, but i don't know what for
i think 0 should be north, 90 east, 180 south, 290 west after that adjustment
or if we are 180 degrees wrong, then you subtract instead of add in that calculation to fix it
and if the game rotation goes counter-clockwise we would need to flip that number around to fix it

elder cobalt
cloud spruce
cloud spruce
cloud spruce
# elder cobalt ah I see

by the way, i added teleport = True that you can set to False if you just want to see everything printed (like what it would do) but not affect the car in the game

elder cobalt
#

something like a compass

cloud spruce
elder cobalt
#

in case something breaks down

cloud spruce
#

i wonder if they have done some real world modeling in the game when it comes to light direction ๐Ÿค”

elder cobalt
#

iirc you could set the angle of the sun in game

cloud spruce
#

i mean, if they set the correct angle of the sun depending on were on earth the city that you drive in is located (say the map should be located in Monaco) and the date of the year and time of day that the events in game should play out in

cloud spruce
elder cobalt
#

not sure if these could be of any use?

cloud spruce
# elder cobalt not sure if these could be of any use?

it is, since you can set the location of the sun in degrees in relation to the map (heading in there), the height angle doesn't matter much as long as it's not to much overhead, and angle of 20-35 degrees over the horizon is probably fine
we should be able to point the front of the car towards the sun a few times when the sun is in different places and check the X_rot value to see how they relate to each other in game and work out if X_rot is 180 degrees reversed or not and if the whole map is also 90 degrees on it's side and work out the cardinal directions from there

but first we would need to know something more basic, like if X_rot is clockwise or counter-clockwise in the game
and that's easy to check by you just getting the X_rot of the car and then turning the car like 45 degrees to the right (or left, as long as i know which one you did) and then getting the X_rot again

elder cobalt
#

hmm

cloud spruce
elder cobalt
#

will get back to you

elder cobalt
#

@cloud spruce good news found a car in game which has an inbuilt compass

#

took a bit of searching around for old mods

elder cobalt
#

This is from

#

Hmm what type of correlation tho

#

O

#

60 degrees difference

cloud spruce
elder cobalt
#

this seems sorta confusing tho, let's say the difference between heading and rotation of X axis is 60 degrees

#

so when heading's negative rotation is positive and vice versa

cloud spruce
#

what happens with the X_rot value when you start turning right, does it increase or decrease?

elder cobalt
#

hmm let me try real quick

cloud spruce
#

also, somewhere it will flip from positive to negative and when you are close to 0 degrees in-game (which i think should translate to N) what is the X_rot value?

elder cobalt
#

a mb for taking too long, it looks like the server is having a seizure gonna ping you once I can come back with some readings

cloud spruce
elder cobalt
#

I'll load in a server with nothing but just a flat plane that should help getting things started

cloud spruce
#

if the offset between X_rot and north would be 1 radian it would translate to about 57.2958 degrees, can that be what you are seeing?

elder cobalt
#

Basically rounding it off to 60 degrees

elder cobalt
#

So it looks like

#

Car's facing straight?

#

ok it actually corresponds to this nice

#

so east is -90 degrees, -180 and +180 might be south, +90 must be west then 0 and -0 should be North

nova cloud
#

Well yes but also it's easier to work with only degrees between 0 and 360 so I recommend adding 360 to the number until it's positive that way you don't have to keep in mind the number might be negative

elder cobalt
#

thinking of doing that once I get to know NSWE

#

so it looks like

#

-90 = East = 90 in map
0 = South = -180 to +180 in map
90 = West = -90 in map
-179.9 to +179.9 (rounding it to 180) is = North = 0 degrees in map

#

hmm time to convert it to an actual compass

#

o wtf

#

the game does not go to 360 heading as well

#

I guess it'd be pointless to convert it to a full 360 might confuse the game

#

I guess implementing a cardinal direction : it's heading degrees will be better

tired river
#

Can anyone tell me is CCNA certificate important out there or not?

#

in recruitments u k

cloud spruce
# tired river Can anyone tell me is CCNA certificate important out there or not?

depends on the company recruiting, i have never given much stock to any certifications as our company don't need them, for a consultancy company which offers support contracts to customers or a reseller it can be a requirement either that you have them or get them soon after employment
we had a similar discussion about certifications in #cybersecurity a while back which then was generalized to most higher certifications within IT, it's around this point in the chat history of that channel: #cybersecurity message

wanton dock
#

do guys have an idea how for an program in the field of networking?

cloud spruce
wanton dock
cloud spruce
# wanton dock so i coded a litle file server (more or less a cloud) wich was a great project...

it's impossible for us to say what you will think will be a fun project or a project on the right level (not too hard and not too easy either), which makes it very hard to come with suggestions ๐Ÿคท
it's best if you pick something you are passionate about or something you feel you are lacking (that you are in need of), that will make it easier to find motivation to work on the project

elder cobalt
#
def compass_direction_name(angle: float):
    angle = angle % 360
    octant = round(angle / 45)
    return {
        0: "S",
        1: "SW",
        2: "W",
        3: "NW",
        4: "N",
        5: "NE",
        6: "E",
        7: "SE",
        8: "S"
    }[octant]

print(compass_direction_name(math.degrees(struct.unpack('<f', X_rot)[0])))

You think these are enough to get a compass?

#

here's a rough sketch

#

Hmm now I need to figure out it's heading ๐Ÿ˜… took a while to make the compass and correct it @cloud spruce

cloud spruce
cloud spruce
elder cobalt
cloud spruce
elder cobalt
#

let me just recheck for the rest

cloud spruce
# elder cobalt

what is X_rot from the packets in radians if you are heading as close to north as you can?

elder cobalt
cloud spruce
#

like, without any adjustments, the raw X_rot of the car in radians

elder cobalt
#

true north is supposed to be -3.14 or 3.14

#

if it goes beyond -3.14 it jumps to +3.14 and vice versa

#

its just that because the car keeps moving I can't get the exact

#

3.14 radians

#

but very close

cloud spruce
#

and east is then close to -1.57?

elder cobalt
#

Yeah

cloud spruce
#

now i see, it's because everything is flipped around 180 degrees or 1 pi radians

elder cobalt
#

Exact -1.57

#

Hmm you think we would be able to get heading in degrees with this?

#

Problem is heading is supposed to be calculated till 360 maybe I'll put an indication saying that if it's 360 it's (0) and if it's 270 then it indicates (-90)?

cloud spruce
#

yeah, no problem, now when we know how the X_rot in the data packets works in relation to the game world

#

well, 0 = 360, usually it's 0 .. 359,99999... and then you wrap around to 0 again

elder cobalt
#

Hmm any idea on how to implement? My rough guess is we take X_rot and add or multiply to it? @cloud spruce

cloud spruce
elder cobalt
#

yep working perfectly!

cloud spruce
#

taking + math.pi removes any negative numbers and turns the heading so that 0 radians is north, 0.5 pi is east, 1 pi is south and 1.5 pi is west

elder cobalt
#

using these two print statements atm

#
        print(compass_direction_name(math.degrees(struct.unpack('<f', X_rot)[0])))
        print(round(math.degrees((struct.unpack('<f', X_rot)[0] + math.pi))))
#

really bad when it comes to formatting stuff into something readable ๐Ÿ˜…

cloud spruce
#

if you still have that function defined in your file

#

and you can define your function as def compass_direction_name(angle: float) -> str: if you want full type hints

cloud spruce
elder cobalt
#

now I guess it's time for me to start decoding modded server packets ๐Ÿ˜ฉ

#

Thanks for helping me out soo far @cloud spruce

#

really mean it ๐Ÿ™‚ wouldn't have got this far without any of your help

cloud spruce
elder cobalt
#

it looks like for modded packets there's an identifier after the type which indicates how many updates are there in that one single packet

#

only problem is that now I need to say python to look for the numberOfUpdates byte packet then based on that search through the packets with the sessionID which you are trying to find then splice the data accordingly

#

problem is that how would I say python to make sure it searches for the right data ๐Ÿค” then say python that entire struct is belonging to this sessionID?

#

isn't as simple as the + offset but not sure

#

fortunately it follows the same structure

cloud spruce
#

but i must again say that i really liked kaitai ๐Ÿ™‚

elder cobalt
#

was a breeze to setup things and start working with the packets though

cloud spruce
#

or are you required to make it into a bytearray first?

elder cobalt
#

data = bytearray(packet.payload)

cloud spruce
#

i'm just checking if there is another way to do a few things which would be an advantage when processing the modded server packets

elder cobalt
cloud spruce
#

or at least read the data when it's data from the server

topaz dune
#

Heyyy
Anybody knows a way to send files from my pc to a friend(different network) through terminal?

#

we both have linux

elder cobalt
cloud spruce
cloud spruce
elder cobalt
topaz dune
elder cobalt
#

@cloud spruce ```python
import pydivert

with pydivert.WinDivert("ip.DstAddr = 87.106.198.64 and udp.PayloadLength = 62") as w:
for packet in w:
print(packet.payload)
w.send(packet)
break


Get the output as

```b"FBQ\x90\x02\x00'\xb8\x13D\xcd\xe9\xb5B.\xd8\xb3D\x14\x10\x06\xc0\xaf\xb6n\xbd\xb8\x08\x1b\xbd@Z.\xbb\xbfh\x8b:\x13\xd5q:dddd\x7f\x7f\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd6\x94m?"```
#

looks good?

elder cobalt
#

sorry didn't look through your message properly

cloud spruce
elder cobalt
#

That's how I got the compass to work

cloud spruce
ember ledge
#

hi what to learn here. what about networking if I may ask

cloud spruce
# elder cobalt Yep

nice, then we can use another pretty cool python feature to access each packet segment ๐Ÿ™‚

ember ledge
#

is it like "hackers" here?

cloud spruce
# ember ledge is it like "hackers" here?

nope, unless you go back to the original meaning of the word "hacker" which meant something along the lines of "tinkerer" and would today probably be more in line of what is now called a "maker" ๐Ÿ˜‰
at the core what a real hacker is hasn't changed, it's a person that takes a thing that is made to do something(s) and make it do something else that it wasn't originally made to do but you would like it to do instead
that is basically what today's definition of hackers is still about if you think about it and filter out the pop culture around the word

elder cobalt
elder cobalt
# cloud spruce nope, unless you go back to the original meaning of the word "hacker" which mean...

I still recollect a quote somewhere stating that it takes only one programming language to master and you can kick start with anything network related.

To be honest, I'm glad I've taken python partially because of how it was taught at school but more over on how easy it is to understand and how versatile it is, idk I've been thinking about getting into lua or c/c++ down the line but python just keeps pulling me back, maybe because of how I'm somewhat familiar with it and if I ever wanted to integrate with any other field maybe not solely into computer software but hardware related it'd be easy to do so with a bit of tinkering

#

To be short I just like tinkering with stuff on the hardware level, packets and networks grasped my attention after learning how easy it is to get started with python

undone harbor
#

does anyone know how to create sftp server with python

elder cobalt
#

game heading does not correspond at all

#
game_heading = round(math.degrees((to_float(X_rot) * -1)))

might be because of the * -1

cloud spruce
elder cobalt
#

for instance

#

car rotation in rads

#

the compass heading works fine tho

cloud spruce
elder cobalt
#

so * -180?

#

woops

cloud spruce
elder cobalt
#

but game calculates between 180 to -180

cloud spruce
elder cobalt
#
real_heading = round(math.degrees((to_float(X_rot) + math.pi)))

I use this variable to show from 0 to 360

cloud spruce
#

the + math.pi will make the compass go from 0 - 359 degrees instead of -180 - +180

elder cobalt
#

a is there anyway to show between -180 to +180?

cloud spruce
#

oh, you want the negative heading as well?

elder cobalt
#

yeah

cloud spruce
#

but you want it flipped so that 0 is north instead of south?

elder cobalt
elder cobalt
#

well I made a dict not sure if I can use the same here

#
def compass_direction_name(angle: float) -> str:
    angle = angle % 360
    octant = round(angle / 45)
    return {
        0: "S",
        1: "SW",
        2: "W",
        3: "NW",
        4: "N",
        5: "NE",
        6: "E",
        7: "SE",
        8: "S"
    }[octant]```
cloud spruce
elder cobalt
#

ig I drew the diagram wrong when I was editing it

#

north should be up and south should be down

#

there

elder cobalt
#

Hmm any luck? @cloud spruce maybe should I like create some conditions for + and - events?

cloud spruce
halcyon lily
#

Hi, I'm not sure if I'm posting in the good channel. I tried positing my question in a help channel but got no answer. I have something I don't understand, mostly because I'm a beginner with sockets. I wanted to know if there is any possibility that a recv could be blocking (or stuck) with a socket put in non-blocking state, when having check before with a select if there was data

#

This is the link to my question if by any chance someone have an idea

elder cobalt
cloud spruce
halcyon lily
#

I'm on macOS

#

I am checking in a loop with select if there is any data in reading for my socket. then if there is, I'm doing a recv. My problem happens like 1 or 2 times in a day

#

So it's not something happening each time and it's very hard to reproduce

#

If the socket is stopping from the other side, while doing a recv, I'm expecting to have an error that I would catch, but it seems I'm stuck in the recv while having set sock.setblocking(0) so not sure what could be happening here

cloud spruce
# elder cobalt Huh so I guess doing a comparison with radians itself and then converting them t...

can't really test, but a complete compass.py might look something like this:

import math

import pydivert

server_address = "146.19.191.145"
server_port = 9948
Session_ID = 12
# 0 = N, 90 = E and so on, others may also go in between as long as they are in order
# cardinal_directions = ('N', 'E', 'S', 'W')
cardinal_directions = ("N", "NE", "E", "SE", "S", "SW", "W", "NW")
# cardinal_directions = ('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW')

def cardinal_direction(rad_angle: float) -> (str, float):
    return cardinal_directions[math.floor((rad_angle % math.tau) / rad_cardinal_precision + 0.5) % len(cardinal_directions)], math.degrees(rad_angle % math.tau)

def to_float(data: bytes) -> float:
    return struct.unpack("<f", data)[0]

session_id = struct.pack("<B", Session_ID)
rad_cardinal_precision = math.tau / len(cardinal_directions)

with pydivert.WinDivert(f"(inbound and ip.SrcAddr = {server_address} and udp.SrcPort = {server_port} and udp.PayloadLength > 60)") as divert:
    for packet in divert:
        if packet.direction == pydivert.Direction.INBOUND:
            if packet.payload[1:2] == session_id:
                X_rot = packet.payload[21:25]
                cardinal_heading, degrees_heading = cardinal_direction(to_float(X_rot) + math.pi)
                print(f"{round(degrees_heading):3} degrees, {cardinal_heading}.")

        divert.send(packet)
#

and you can pick which granularity you want for the directions, any of the three should work just fine

#

math.floor(some_float + 0.5) in there is almost like round(some_float) but deals with numbers like 18.5 and 20.5 differently

elder cobalt
#

used

#
def g_compass_convert(radians: float) -> float:
    if to_float(radians) < 0:
        return to_float(radians) + math.pi
    else:
        return to_float(radians) - math.pi

g_compass = round(math.degrees(g_compass_convert(X_rot)),1)
cloud spruce
# elder cobalt ah yikes, I just made my own but will save your copy as well if any case mine br...

the relevant bits are in:

cardinal_directions = ("N", "NE", "E", "SE", "S", "SW", "W", "NW")

def cardinal_direction(rad_angle: float) -> (str, float):
    return cardinal_directions[math.floor((rad_angle % math.tau) / rad_cardinal_precision + 0.5) % len(cardinal_directions)], math.degrees(rad_angle % math.tau)

rad_cardinal_precision = math.tau / len(cardinal_directions)

# loop here
    cardinal_heading, degrees_heading = cardinal_direction(to_float(X_rot) + math.pi)
```and you could also go for a 4 or 16 segment compass with that instead of an 8 segment compass
elder cobalt
#

yeah wanted the cardinal directions so bad lol

#

thanks

cloud spruce
#

tau is the constant of a full circle in radians, 2*pi, what would be 360 degrees

wise jungle
#

glad to see rndpkt is still going strong in #networks

cloud spruce
wise jungle
cloud spruce
cloud spruce
neon horizon
#

Hello, I'm trying to get into socket programming.. I have trouble getting the server and client to send each other messages smoothly..

#

my problem is that when i run the client script, either the client doesn't receive the initial message from the server, or the server doesn't receive what the client has inputed

#

could anyone please help me figure out what's wrong

cloud spruce
neon horizon
#

ok, so i changed the server ip to 127.0.0.1
i also copy pasted someone else's code to see if it works, and if so, how it's different from my code..

#

looks like people don't send the length of a message before sending the actual message..

cloud spruce
cloud spruce
#

i think the problem you are facing is that you get out of sync with the data you expect and the data you get and communications breaks down

#

you would need to have a read loop that fills a buffer variable in your program until you have 64 bytes and then process the header if you are going to use a fixed 64 byte header

neon horizon
#

i was using the fixed buffer because i thought the recv can only receive a certain amount of bytes vs up to a certain amount of bytes

#

would i just send and receive as many bytes as i need without the buffer?

cloud spruce
cloud spruce
#

this goes equally for the server and client programs of course

neon horizon
#

why do i need the fixed header in that case?

#

*what would the header be doing?

cloud spruce
# neon horizon why do i need the fixed header in that case?

you don't have to have a header at all, but you would need something to tell your program when a full message is completely received or else it's just a stream of octets (almost like bytes), but certainly not characters
as you are using utf8 which can be multi-byte characters, one utf8 character can be split between two different recv() calls
how would you know it's safe to do decode() on the received bytes, so that a multi-byte character doesn't end up in between two different buffers that you run decode() on separately?

wise jungle
opal orbit
#

I'm trying to implement a full-duplex connection in python with sockets and I'm struggling with this concept, how am I supposed to know if the socket is sending or recving the data? Because calling the wrong method will cause timeout err

cloud spruce
elder cobalt
#

@cloud spruce just a headsup regarding modded server packets, I'm thinking whether I can say python to maybe search 61 bytes each time that way it can see if it has the required information or not, and if that entire packet does not contain it'll just send it to my client and proceed with the next packet? maybe once it finds the required session_ID change the offsets in a way where it splices 61-62 bytes?

opal orbit
cloud spruce
# opal orbit I think the select is the easiest method? I've read that there are other more ef...

one thread per connection is usually simpler and tend to lead to cleaner code as you only have to deal with one connection in the code path
but if you want to exchange data between clients through the server thread can make it a little more complicated instead (as you then need to transfer data between thread in a thread-safe manner)

old fashioned select() is the least efficient, but on Linux and BSD it's nowadays backed by more modern kernel facilities like epoll and kqueue which makes them more efficient then threads

cloud spruce
opal orbit
#

@cloud spruce How would you do it with only threading? Everything I can think off here is quite opposite of clear, like some recursions and cross-connecting classes etc, my head just hurt from thinking about it

cloud spruce
#

also, what kind of data is it and how does the flow of data look (a lot of back and forth, just a request and a response, just a stream, or somewhere in between)?

opal orbit
#

@cloud spruce Im trying to do a basic proxy, one connection is just local with binded port, the other is remote addr, i know there can be issues with some of the protocols hence they have to get some things like banners first before the data but I will try to handle it later after the basic mode works

#

Its pretty ez without the full duplex mode, but some real troubles starts here for me

cloud spruce
opal orbit
#
class ConnRemote(Thread):
    def __init__(self, host:str, port:int): #TODO: Multiple target support
        self.host, self.port = host, port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sock.connect((host, port))
        print('[*] Connection established:', self.sock.getpeername())
        self.data = io.StringIO() 
        self.bytes = 0

    def run(self):
        #   Read only if the previous data where already read,
        #   after the fileptr is being set to 0 again:
        while not self.data.tell: 
            data = self.sock.recv(4096)
            if data:
                self.bytes += data.write(data)


class ConnLocal(Thread):
    def __init__(self, host:str, port:int):
        self.host, self.port = host, port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.bind((host, port))
        self.data = io.StringIO()
        self.bytes = 0

    def run(self):
            self.conn, self.addr = self.sock.accept()
            while not self.data.tell():
                self.bytes = self.data.write(self.sock.recv(4096))


class ConnArt(Thread):
    def __init__(self, lhost:str, lport:int, rhost:str, rport:int):
        self.lhost, self.lport = lhost, lport
        self.rhost, self.rhost = rhost, rport

        self.conn1 = ConnLocal(lhost, lport)
        self.conn2 = ConnRemote(rhost, rport)

    def run(self):
        self.conn2.sendall(self.conn1.data.getvalue())
        self.conn2.data.seek(0)

        self.conn1.sendall(self.conn2.data.getvalue())
        self.conn1.data.seek(0)
    
    def cleanup(self):
        self.conn1.shutdown()
        self.conn1.close()
        self.conn2.shutdown()
        self.conn2.close()
    
    def stats(self):
        return self.conn1.bytes, self.conn2.bytes

Idk I guess im just too dumb, it feels bit easier to work with sockets in old c though, more explicit

cloud spruce
# opal orbit ```py class ConnRemote(Thread): def __init__(self, host:str, port:int): #TOD...

i think you would get problems if you use separate threads for the local and remote connection, then you need a queue to transfer data between them in a thread-safe way
https://docs.python.org/3/library/queue.html
this is what i meant that threads can be kind of a problem if you need to share data between connections/threads
you might want to keep the pair of connections in the same thread and do select() between them instead
or just drop threads all together and switch over to asyncio, i think that would be the best option for you really if you are willing to take the plunge and get in on async programming (if you haven't already)
besides the standard library module asyncio you could check third party modules like Trio which also has awesome documentation for learning async programming and concepts
asynchronous programming is the most scalable option (and doesn't have the overhead of threads and no problems with thread safety) you have if your program is mostly io bound

cloud spruce
opal orbit
#

Okay, thanks, there is a lot to look into, I think I'm gonna try building both threading and async versions for learning purposes. I was taught that threading is superior, but I guess asyncio has its strong points too

cloud spruce
# opal orbit Okay, thanks, there is a lot to look into, I think I'm gonna try building both t...

to be blunt, threading is quite inferior for I/O bound workloads (more or less regardless of language) compared to async io implementation due to the overhead incurred by starting threads and context switching done by the OS, add to that the total lack of control of when context switching and execution of a thread happens
threading in python is also unsuitable for cpu bound loads due to pythons GIL, for such loads you need to go with multi-process when using python
unless you are calling C/C++ libraries that explicitly release the GIL for some of it's work, which they can't do while exchanging data with the python parts of the code

elder cobalt
#

@cloud spruce guess I'm pretty much stuck with decoding modded packets lol, can't really find a way to implement it the way I imagine

#

can't seem to splice particular parts of the data payload

cloud spruce
elder cobalt
#

Mine just doesn't work ๐Ÿ˜”

shy lion
#

hello, can i ask here somthing about netmiko and linux ?

cloud spruce
edgy scroll
#

Is there anyone work as a freelancer? I wanna start a freelance career. I would appreciate it if you guys help me out.

ripe spear
edgy scroll
#

Actually im gonna work in data science and ml besides i dont have a degree. Do they care?

green siren
#

Kind of a broad question unfortunately,

I am creating a server that will be accepting TCP connections from multiple users, they will be logging in, and then accessing/querying/changing data inside of a Postgres database I have setup.

I plan on setting each TCP Connection inside its own thread so I don't have to close them, as I plan on users regularly querying new data (I shouldn't have to close it and reopen it constantly, should I?)

Can each thread push a query to the database without me worrying about creating some kind of queue, or locking a stand-alone thread that passes these queries to the database?

Does the database handle all concurrency issues by default?
Will I have an issue on pythons end by pushing multiple queries out at the same time?

cloud spruce
green siren
#

Not sure if making fun of my question or a serious question ๐Ÿค”

cloud spruce
#

starting what within networking exactly?

cloud spruce
green siren
#

Don't think I've ever used async io or asyncpg how is it different?

And what do you mean connection pool towards the database

cloud spruce
# green siren Don't think I've ever used async io or asyncpg how is it different? And what do...

with any kind of async io you typically run everything in only one thread (or at least a low number of threads) and you may write functions what you declare as async
then you call your own and other async functions from different libraries with await which tells your program "this call might take a while before it returns, while we wait the program can go on and do there tasks in the meantime, then when this call eventually is finished we'll continue with the execution where we left off"
for asyncpg specifically, see: https://github.com/MagicStack/asyncpg and https://magicstack.github.io/asyncpg/current/
and to use it with connection pooling towards the database, see: https://magicstack.github.io/asyncpg/current/usage.html#connection-pools (remember that this is just an example, there are probably better libraries for you then aiohttp that is used in that example, as connection pooling has nothing to do with aiohttp specifically)

#

i think this is a very good tutorial to start with: https://realpython.com/python-sockets/
but where they use recv(1024) i would use a slightly higher multiple of 1024, at least 2048 in general and maybe higher numbers still, such as 4096, 8192 or 16384 in LAN environments that support jumbo frames (which isn't very common)

cloud spruce
elder cobalt
#

btw @cloud spruce you think it's better to use sockets or pydivert in the long run? So far I'm doing just fine with pydivert but not sure if I should branch out and learn sockets as well?

cloud spruce
wise jungle
#

ok so how would u actually use UDP in async?

#

i assume you dont just slap async into the function ofcourse

wise jungle
#

@cloud spruce

green siren
green siren
wise jungle
#

for tcp sockets its fine to use multi threading

#

but then later on its ideal to get into async

#

i still dont know how to but i really think u just turn the functions into async and run the app as a loop

cloud spruce
cloud spruce
wise jungle
#

i maybe able to do it myself but i havent worked with async that much

brave raptor
#

When I do a request like this requests.get(...), how does the site in question know that a script is making the request, not a genuine user? Currently it's returning an access denied error code.

prisma cobalt
#

the user-agent header might yield some infomation

brave raptor
#

oh, do you know if there's a way to print out the header?

prisma cobalt
#
import requests
                 
r = requests.post(API_URL)
# get request headers
print(r.request.headers)
brave raptor
#

ah, thanks

karmic tangle
#

Is this code only or networking as general ? ๐Ÿค” I am trying to find someone that would help me with management switch

cloud spruce
karmic tangle
#

Our IPTV has 2 IPs. One local and one from WAN . Normal switch don't forward both IPs and IPTV doesn't like that.

#

I borrowd managment switch and i wanted to set it but i dont know how.

#

anyone help please?

cloud spruce
karmic tangle
#

mikrotik hEX
ID: RB750Gr3

cloud spruce
karmic tangle
#

yes windows. but i am trying to set it throu web

cloud spruce
karmic tangle
#

when i reset it and conect to pc, i get address

cloud spruce
karmic tangle
#

bouth, i am curently in the switch managmet UI (winbox )

cloud spruce
karmic tangle
#

yeah probably

#

1_INTERNET_R_VID_836 836/0 IPv4
5_TR069_R_VID_851 851/6 IPv4

#

personaly i think, the first is normal internet and the second is for iptv

#

it's quite late here, good night. i will be back in morning

main spruce
#

Does anyone here have experience converting UDP from matlab to python?]

cloud spruce
cloud spruce
main spruce
#

hey @cloud spruce, thanks for responding. I've posted my question in #help-chocolate

wise jungle
#

asyncio udp ๐Ÿ˜„

#

need assistance

#

no clue how to do

#

or just handling multiple clients

#

i dont know what i did wrong

#

im gonna rewrite it

cloud spruce
wise jungle
#

ya i just saw ur ping im gonna read everything

cloud spruce
# wise jungle ya i just saw ur ping im gonna read everything

i think you'll be very happy with working with async when you've got the hang of it
as you would be writing functions or methods to handle events (like when you receive new data on the socket)
then you just have to keep some state like the list of all sockets so that you know where to the incoming data to reach the other participants on the server

wise jungle
#

i love you !

cloud spruce
#

happy to help where i can ๐Ÿ™‚

wise jungle
#

so how is it not non blocking

cloud spruce
#

the idea with async programming is that you should call functions that are declared with the async key word with await (meaning "asynchronously wait")

wise jungle
#

ya dats why i was asking about it

#

cause i dont think this really solves the issue

#

but is part of the solution

cloud spruce
#

functions that can either block or take time to execute because we would have to wait for something like opening, reading or writing a file are declared with async

#

when you call them you use the await key word in the call

#

that tells the program that "while we are waiting for this to finish we can go and do some other work instead"

#

in that way you are in control of at which points in the code context switching can happens, as it only happens when you run await

wise jungle
#

im finna look into it tmrw morning 3 am rn

cloud spruce
# wise jungle im finna look into it tmrw morning 3 am rn

i would recommend the official asyncio documentation at https://docs.python.org/3/library/asyncio.html as it's the most correct and up to date with the current practices for async programming in python
but first you might want an introduction and overview to get to grips with the terminology to find your way around the official documentation
for that i would recommend https://realpython.com/async-io-python/
or another library (not part of the standard library) named Trio https://trio.readthedocs.io/en/stable/ which has very good documentation and tutorials on the subject even if it's understandably kind of bias towards their own library, but don't let that discourage you from reading it as they still teach the general basics of asynchronous programming, and in the process you might also come to appreciate or even like their library ๐Ÿ˜‰

elder cobalt
#

Btw @cloud spruce you think making some sort of a counter where it keeps adding +61 to check the sessionID since all of them are evenly spaced? That way if it does hit the correct sessionID it'll apply offsets automatically to other variables, and if the counter reaches the max counter of the packet it implies that the sessionID does not exist in this packet and it'll simply send and then look into the next packet sent

wise jungle
#

okay before i get into async and all dat i managed to clean up the code from github

#

i will do some tests now

light brook
#

I need list pip python libraries for network analyzer

quick moat
#

hello
should https stuff be setup in gunicorn or in nginx?

#

i have flask --> gunicorn --> nginx

karmic tangle
#

so, i solved my Router problem. ๐Ÿ˜„ now to the code... ๐Ÿ˜„

#

mikrotik > RouterOS... anyone? ๐Ÿ˜„

cloud spruce
cloud spruce
quick moat
#

oki

#

thank your

cloud spruce
# quick moat thank your

but most people can do without using TLS between the nginx and app server instance even if they run on different servers or containers as long as they are on a private network and don't have very strict security requirements impost on them

quick moat
#

its on same machine

#

no need https if between two containers?

#

for backend api

cloud spruce
# quick moat no need https if between two containers?

if it's on the same machine and you don't let other people in to that machine, then no
unless you are really paranoid or work for a company with very strict security requirements
just see to it that your gunicorn instance isn't accessible from outside in any way

quick moat
#

ok

wise jungle
#

have u heard of cyberpanel before @cloud spruce

cloud spruce
wise jungle
#

pretty handy

cloud spruce
wise jungle
#

kinda old but quiet convenient

#

and its constantly updated

cloud spruce
#

what is?

wise jungle
#

cyberpanel

elder cobalt
#

@cloud spruce for some reason this code does not work ๐Ÿ™ https://paste.pythondiscord.com/ozesuxevih any idea?

I'm trying to create a counter where if it's not equal to packet counter it will jump to the next if statement where if the data spliced location(with offsets) is equal to the session_ID specified it will print out the XYZ and etc., else it'll keep adding +1 to the counter so that the next time it runs this loop it'll do 1 + 2 + 60 * 1 such that it'll read rest of the packet data before fully discarding it.

But let's say if that packet does not contain any info from the specified session_ID, and my counter is greater or equal to the packet counter it will set the counter back to 0 and continue to send packets that way it can proceed to the next packet. Is this flawed or are there any other ways to improve this? because my count loop seems to keep increasing to 100s and 200s which I am sure has most likely crossed my packet counter

light brook
#

@mdpkt

#

trafic

#

โš—๏ธ

main spruce
#

Hey guys, I currently have some networking code that is connecting to the host server and the host server confirms connection; however when i run s.recvfrom(1024) my python interpreter hangs up and I have to kill the process. I've tried adding a timeout and a try/except block but regardless the interpreter still hangs up

#

Anyone ever experienced this before, it's a udp port

steady horizon
#

socket.socket.recvfrom intentionally hangs until it receives 1024 bytes of information

#

Actually I don't remember whether it waits for the entire 1024 bytes of information to be received or it returns as soon as a packet with โ‰ค 1024 bytes of information

cloud spruce
#

s.recvfrom(1024) will return as soon as there is any data available, with as much data that is available at that time, up to and including the requested number of bytes (in this example 1024 bytes inclusive)

#

so, there shouldn't be a problem

cloud spruce
cloud spruce
# elder cobalt <@936769916072259654> for some reason this code does not work ๐Ÿ™ https://paste.p...

i was quite busy during the weekend and didn't have much time to write and test code
but today i have had some time to look into this and i got something that should work
i'm just not super happy with the performance of it yet, so i'm trying a "few" different things ๐Ÿ˜‰
spoiler alert: i tried to use kaitai in the python code, it was unfortunately the slowest of all the things i have tried yet in my benchmarks for this specific problem

elder cobalt
#

I took your implementation and tried changing it in a way that offsets get multiplied by a counter * 60

cloud spruce
#

or, well. not always the slowest, but for the modded server it was really slow as it always decodes everything from all instances

elder cobalt
#

o I see

cloud spruce
#

i wanted to try it out as i have never used it in python before ๐Ÿ˜

elder cobalt
#

I guess it'll be useful for small projects

#

or places where you don't need to decode stuff very rapidly

cloud spruce
#

yeah, it was quite nice to work with in python as well (not just the webui)

#

just had to find out how to use it with python as that specific part of the documentation was quite lacking

#

but after checking some source code it was quite obvious, so not really a big problem

elder cobalt
#

I just did some debugging from my code and it looks like the counter keeps going towards 200+ which I am sure has most likely satisfied this statement,

            elif counter >= struct.unpack("<B", packet_counter)[0]:
                counter = 0

but for some reason it's not resetting the counter so it looks like it's likely failing this else if check and just keeps adding, perhaps should I send you the full code?

cloud spruce
#

i think i'll going to write a custom class to deal with the data instead where i can tailor for the specific task to optimize it for speed, as this otherwise will add unnecessary latency to the communications in both direction between server and client

#

the extra latency between the server and the client is due to that we halt the packets on their way in both directions to be able to do modifications on them before we release them to let them continue on there way

#

that's why i think we should try to optimize this a bit more for speed than the current implementation

elder cobalt
cloud spruce
#

well, it would have been quicker if i have had more time to dedicate to this

elder cobalt
elder cobalt
cloud spruce
#

there is one thing i have been thinking of trying, but i think i'll just skip it for now since i don't even know if the idea is viable at all, but if it works it might be the most performant

elder cobalt
#

Kinda wished the modded server packets were like the stock lol

#

But ig makes sense if the server wants to offload most of the packets to client

main spruce
cloud spruce
# main spruce i'm running windows 10, python 3.9.7

should work much the same, just know that non-blocking io is wonky on windows and while select() does work it's highly inefficient and doesn't scale well on windows
if my memory is correct i've also seen problems if attempting to use a timeout of exactly zero as that is kind of non-blocking territory, instead use something just above zero, like 0.000001 instead of zero if a zero timeout would be desired on windows, but many times select is better to use with a longer timeout or even without a timeout if the program doesn't need to do periodic or other tasks in between

minor creek
#

iโ€™m good with radios

steady horizon
#

If you want asynchronous networking you can use asyncio

#

It's not as low level as socket though

random dock
#

is there some stron boy from networks in debian?

ember ledge
#

Hi, I am a complete newb to UDP and sockets. I have a python script that attaches itself to a UDP on initialization. It has multiple methods that each send data to that UDP.

The problem Iโ€™m having is that after I call one method, that method will take control of the UDP. So when I try to call the same method again or another method that wants to send data over that same UDP, it wont let me do that.

My question is: how can I attach all my methods to the same UDP so they all can send data to the UDP?

#

@steady horizon

cloud spruce
elder cobalt
#

@cloud spruce any luck? thinkies or maybe any idea where I could start?

deft sonnet
#

raw_data, addr = conn.recvfrom(65535) # Conn receives from '65535'
OSError: [WinError 10022] An invalid argument was supplied

deft sonnet
#

?

mighty sand
#

Hey ! did you ever have an issue with aiohttp failing during an assertion port is not None ? i have no idea why because when i test the query manually it works fine

mighty sand
# proud swift Do you have a traceback?
  File "/usr/app/[...].py", line 77, in execute
    async with session.post(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1146, in _create_direct_connection
    assert port is not None
AssertionError```
#

i have higher trace back for my function stack but the error comes from an aiohttp.ClientSession.post

#

basic aiohttp query code that looks like this

async with aiohttp.ClientSession() as session:
    async with session.post(
        self.url,
        headers=self.headers,
        json={"query": BULK_QUERY_TEMPLATE, "variables": {"query": self.query}},
    ) as res:
        response = await res.json()

which i've tested the query manually

proud swift
#

Manually?

mighty sand
#

i made the post query myself in insomnia

#

it's a graphql query

proud swift
proud swift
mighty sand
#

na cause it's sensitive information :/
bulk query to a shopify endpoint, if you know the API

#

i can give you the exact endpoint if needed

proud swift
#

Try a breakpoint at the line that fails?

mighty sand
#

yes i've already done that, and as i said, previous code isn't important as the query is right, and it works

#

problem seems to come from aiohttp or how i pass the query to aiohttp

#

looking at the stacktrace, the issue seems to come from the connection part so maybe the headers prefetch fails, i'm gonna retry and see

deft sonnet
#

raw_data, addr = conn.recvfrom(65535) # 'Conn' receives from '65535'
OSError: [WinError 10022] An invalid argument was supplied

cloud spruce
mighty sand
#

Ye it does

proud swift
proud swift
mighty sand
#

i have a meeting but ill tell you after

ember ledge
#

can someone help me with a slow loris ddos attack

prisma cobalt
#

no

#

sorry

#

!rule 5

errant bayBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

cloud spruce
ember ledge
#

Permission

#

Iam not breaking any laws

cloud spruce
stuck pivot
#

Ima go

ember ledge
#

Ok i nevermind then

#

Have a good day

main spruce
#

When I open a UDP connection in python via socket
is it possible to open/write/read using that socket? Like how t is defined

dusty shoal
#

How to send inputs using socket

#

TCP

sweet breach
sweet breach
dusty shoal
#

yes

elder cobalt
#

hmm @cloud spruce found something interesting, it looks like my counter is really slow at catching up to my packet_counter? ๐Ÿค” (I've did a print statement to check if counter>=packet_counter)

cloud spruce
elder cobalt
#

this is so far my latest modification

#

I'm using counter to iterate everything being received from the server

#

like every byte being received

cloud spruce
elder cobalt
#

I'm using my own counter and based on that do some conditions like,

If my counter does not match the packet_counter keep adding +1 in hope that I find a sessionID matching the one I want, if it does it'll change the offsets accordingly with the counter variable and print out X, Y and Z of the car's position then reset it back to 0 so that it can start from 0 for the next packet

If let's say my counter variable is equal to my packet_counter or greater than that reset the counter to 0, it implies that this specific UDP packet didn't contain the sessionID I wanted but maybe the next UDP packet will so put it back to 0 and start reading from first

#

if you notice

if data[1 + offset : 2 + offset] == Session_ID:

Here in the offset variable, I did

offset = 2 + reader

and the reader variable is

reader = 60 * counter
#

so let's say my counter is 0, offset will be 2+60*0 which is 2

#

then it'll do

if data[1 + 2 : 2 + 2] == Session_ID

which is basically

if data[3:4] == Session_ID
#

but if it does not match my Session_ID, then I say the counter to add +1

counter=1
reader = 60 * 1 # Which is 60
offset = 2 + 60 * 1 #Which is 62
if data[1 + 62 : 2 + 62] == Session_ID  # Basically data[63:64] == Session_ID
#

@cloud spruce hopefully this makes sense ๐Ÿค”

#

only issue is now my counter is so slow that it can't iterate through all the data before the server sends the next UDP packet with a new packet_counter

#

and that might be why python might be confused and just keeps adding +1

#

but I'm not sure if there's any other way to refine this

#

this is already fast enough because it's only comparing sessionID sent from server to the sessionID I want

#

I could maybe make a delay between the server sending information to the client but that would noticeably create both lag from my side and I won't get information as quick as what the servers sending

arctic meadow
#

hi i am working on a socket program i need to have a list of clients connect to my socket and pass that data to api as a json form when i try to convert the clients socket object to a json object i got an error TypeError: Object of type socket is not JSON serializable so how can i convert my socket object to a json object

main forum
#

idk if this is the right place to ask but its a networking problem ๐Ÿ˜„

#

can someone help me configure the /etc/network/interfaces

#

i seem to do something wrong and it pisses me off

cloud spruce
cloud spruce
# elder cobalt <@936769916072259654> hopefully this makes sense ๐Ÿค”

i'm still struggling with a bug or two in my mocking code that i have built so that i can run the rest of the code and verify if it's working or not
for the fake packets i'm using the .bin files from the archive you posted previously
if i can just get this sorted I think i'll have something to send you really soon
unfortunately i'm away from the computer for a few more hours until i can continue

elder cobalt
#

Also glad you found the .bin files useful I should've provided them from the start lol

elder cobalt
#

@cloud spruce sorry for pinging you but I'm not sure if you've caught up to this but I just realised that the SessionIDs are in +1 order so if it starts with 46, and the packet_counter is 6, it implies 46+6 46,47,48,49,50,51,52 are all the sessionIDs in the packet

#

This could be a way for python to just add the starting number and check if the sessionID I want even exists and if it does not it'll just skip

#

But in the event it does exist let's say my sessionID I want is 48, I'd need to ask python to add 46 to some number which will give 48 (which is 46+2) that way it's way quicker

elder cobalt
#

woops looks like this didn't work out in the end as well

#

๐Ÿ˜…

#

looking forward to your code, ngl I feel like I've tried out everything but for some reason it just does not work

#

Really frustrating ngl, thought this could've worked but nope

main spruce
main spruce
#

Does anyone have experience defining a udp socket using asyncio

cloud spruce
main spruce
#

do you have any examples?

cloud spruce
#

we can continue in there ๐Ÿ‘
but didn't understand what you wanted to do exactly
do you want to setup a firewall?

cloud spruce
ember ledge
#

i hope this is where you ask iptable related questions.. if not please reply with the correct channel, ty

just wondering if theres a way to track udp packets that are being sent to various ports by a single host that are malicious?
(kind of like tcp-connection rate-limiting)

cloud spruce
ember ledge
cloud spruce
ember ledge
cloud spruce
ember ledge
#

can i show you what im doing? i think it would be alot better to see what im talking about

cloud spruce
ember ledge
#

this is an OVH VPS that should block basic attacks and ive added my own iptables so its pretty hard to push unwanted traffic through,

the server im sending the data with is pushing all of its bandwidth through the firewall(s) (which none of it should go through...)
the data thats being sent is malicious but somewhat disguised because its going to its designated port (ex... telnet goes to port 23)
source of packet data: https://github.com/Phenomite/AMP-Research

GitHub

Research on UDP/TCP amplification vectors, payloads and mitigations against their use in DDoS Attacks - GitHub - Phenomite/AMP-Research: Research on UDP/TCP amplification vectors, payloads and miti...

#

im not well educated on networking terms, i hope you get what i mean by packet data

#

im just trying to track this... somehow...

ember ledge
#

yeah my bad

cloud spruce
ember ledge
#

like, able to control... rate-limit or drop.. etc...

cloud spruce
#

if you know the port or the source ip addresses you could, but only to a point since they might be able to fill your uplink if you filer the traffic after that point
in such cases you need external helt from a service provider with more bandwidth then the collective bandwidth of the attackers
there are lots of provider that offers these DDoS protection service at a premium rates
cloudflare even has a decent basic service for free

ember ledge
#

thank you for your time

spare rose
#

Any easy way to calculate time taken to send certain mb of data between 2 cities?

cloud spruce
cloud spruce
spare rose
#

I mean will ping stats be approx same as sending even 1kb/1mb/1gb/1tb of data proportionately?

cloud spruce
dusty shoal
#
import socket

s = socket.socket()
print("Socket created")

s.bind(("localhost", 9999))

s.listen(3)
print("Waiting for connections")

while True:
    c, addr = s.accept()
    name = c.recv(1024).decode()
    print("Connected with ", addr, name)
    while True:
        c.send(bytes(f"Hello, {name}, welcome to the world of coding", "utf-8"))
        output = c.recv(1024).decode()
        print(output)
        if int(output) < 12:
            print(f"Client {name} not eligible")
            c.send(bytes("Folks it looks like your age is a bit lower than expected.", "utf-8"))
        else:
            print(f"Client {name} with age: {output} accepted")
            c.send(bytes("Folks your age is enough to countinue."))
        c.close()
#

Server Side

#
import socket
import time
c = socket.socket()
command = ""
c.connect(("localhost", 9999))
name = input("Enter your name: ")
c.send(bytes(name, 'utf-8'))
print(c.recv(1024).decode())
age = int(input("Age: "))
c.send(bytes(age))
#

Client Side

#
Socket created
Waiting for connections
Connected with  ('127.0.0.1', 63519) Loss
           
Traceback (most recent call last):
  File "C:\Users\Pytho\IdeaProjects\socks\server.py", line 19, in <module>
    if int(output) < 12:
ValueError: invalid literal for int() with base 10: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
#

Error

#

@humble island can you help?

humble island
#

i'm trying to think of something, but this isn't really a networking issue

#

just converting numbers from one base to another

dusty shoal
#

oh so the base of the numbers are different?

humble island
#

this is in hex, isn't it?

dusty shoal
#

oh yes yes i converted it into bytes because that is the only way to send from client to server and vice versa

humble island
#

right

#

the issue is converting from bytes back to int

dusty shoal
#

the this i converted bytes to string and then to int

#

i actua;lly printed the output

#

as you can seee the characters are not identified

humble island
#

i'm aware, i'm trying to see how to convert that back to its

dusty shoal
#

oh wait i already converted it into int

#

age = int(input("Age: ")) , it is converted to int already

humble island
#

you want something like int.from_bytes(mystr.encode('utf-8'), 'big'), maybe? though idk which endiannness you used

dusty shoal
#

i also forgot to mention the encoding

#

yes it worked

humble island
#

i'm not sure about the part where you do bytes(age) though

dusty shoal
#

oh oh the another error

#
Traceback (most recent call last):
  File "C:\Users\Pytho\IdeaProjects\socks\server.py", line 16, in <module>
    c.send(bytes(f"Hello, {name}, welcome to the world of coding", "utf-8"))
OSError: [WinError 10038] An operation was attempted on something that is not a socket
#

@humble island any alternatives for socket?

viscid cipher
#

Generic question: someone knows how to calc the limit of data that i can send as a post request to a server before it gives me gateway timeout error?

cloud spruce
# dusty shoal ```py Traceback (most recent call last): File "C:\Users\Pytho\IdeaProjects\soc...

is this the second pass through the code?
because you are doing c.close() in the inner while True loop
then the second time through the loop the socket will have been discarded and would lead to such an error
instead remove one level of indentation from the c.close() line of code so that it is only within the scope of the outer while True loop
also, you would need some error handling to take care of the case where the client disconnects by doing something like:

    name = c.recv(1024).decode()
    if output is None:
        break
    print("Connected with ", addr, name)
    while True:
        c.send(bytes(f"Hello, {name}, welcome to the world of coding", "utf-8"))
        output = c.recv(1024).decode()
        if output is None:
            break
        print(output)
cloud spruce
# dusty shoal <@467435887236612106> any alternatives for socket?

you will always use sockets in one way or another when doing [normal] network programming or else you would have to circumvent the OS network stack
but you may use high level libraries and functions that hides it from you by abstracting it way (out of sight, out of mind ๐Ÿ˜‰)

dusty shoal
#

@cloud spruce Thanks for the suggestion and code!

cloud spruce
cloud spruce
dusty shoal
#

so should i make a list of questions would tahtb efficient?

#

that be*

#

if yes then can you show how, (again i'm very very new to this stuff, though it is quite interesting)

#

@cloud spruce ?

cloud spruce
#

in the server you could send the question just prior to the line where you do s.recv() and wait for the answer
but the client would have to be reworked a bit

dusty shoal
#

also how can i send inputs to the user as send?

#

and yes I hereby confirm that I am total moron

cloud spruce
#

you wouldn't send the inputs to the user, just the text string with the question as bytes
the client would just s.recv() the question use it in the input() on the client

dusty shoal
#

how to send multiple inputs?

#

ir. text strings

cloud spruce
#

just loop in the client as well

dusty shoal
#

so a for loop in the while true loop in the client and a for loop in the client am i right?

cloud spruce
# dusty shoal so a for loop in the while true loop in the client and a for loop in the client ...

no need for any for loops and you can keep your server mostly as it is, just put a s.send() with the question before each s.recv() and handle all input() as strings (not int) and send it over to the server as the string converted to bytes and do the conversion on the server slightly different
in the client, just do something like:

while True:
    question = c.recv(2048).decode()
    if question is None:
        print("The server closed the connection.")
        break
    answer = input(question)
    if answer == "":
        break
    c.send(bytes(answer, 'utf-8'))
    reply = c.recv(2048).decode()
    if reply is None:
        print("The server closed the connection.")
        break
    print(reply)
c.close()
burnt quartz
#

anybody here?

cedar forum
#

yep

main spruce
#

is it possible to check if data was sent to a UDP port

#

via cmd

main spruce
#

or i guess received

#

right now im using netstat -sp udp

#

but i want to specify one port

cloud spruce
# main spruce is it possible to check if data was sent to a UDP port

you need the process to be bound to the UDP port at the time your machine receive the packets or the packets will be discarded by the OS
the corner case is if you use raw sockets, it can be used like a sniffer for both inbound and outbound traffic on an interface but requires you to have superuser privileges

#

on linux you can use iptables to count the packets to a specific port if you make a specific rule for that port

cloud spruce
# main spruce but i want to specify one port

the you need to bind to that port with your program or setup a firewall rule with counters that you can check or use a raw socket och other way to sniff traffic preferably with a filter and then count it

main spruce
#

when I run netstat -sp udp

#

and my program

#

I see packets are sent/received

#

but I also have a bunch of receive errors

#

but netstat -sp udp is for every udp port

#

I want it for just one

cloud spruce
#

or use a firewall rule for one port and make the firewall rule count the packets for you, then you don't need anything listening on the port

#

or have an application that sniff packets and count the matching packets that way

main spruce
#

so that's the issue

#

my server registers my client's send request and sends packets to the client

#

but the client isnt registering the data for some reason

#

basically my socket.recv() isn't returning anything except a timeout

#

I know the program is sending it to the port

#

I want to know if the port is receiving it

cloud spruce
main spruce
#

Iโ€™m on Windows

#

Is there no way to do it without external program

cloud spruce
cloud spruce
main spruce
#

I need something either in code, in a terminal, or cli

main spruce
cloud spruce
#

wireshark comes with tshark, it's more or less the same thing for the cli (in both windows, linux and mac)

elder cobalt
#

a @cloud spruce lmk if you need more packets to test with, perhaps you could use a wireshark file to maybe replay all the packets instead of .bin files?

cloud spruce
# elder cobalt a <@936769916072259654> lmk if you need more packets to test with, perhaps you c...

thanks, that would have been an idea, but now i have built some mocking code for use with the .bin files where there is only the payload of one packet per .bin file
otherwise i would need to write something custom again for reading in the pcap file and extracting the payload and doing something similar with it
would probably not be a lot of work now when i already have an mvp for creating fake packets with payload compatible with pydivert

cloud spruce
main spruce
cedar forum
#

what do you mean can't display

#

tcpdump is another good bet

cloud spruce
cloud spruce
cedar forum
#

right that's true, in that case I'd probably do netsh tracing and then import into wireshark/tshark

#

don't have to necessarily capture with wireshark if that's playing up

cloud spruce
cedar forum
#

i've done packet tracing on windows server once so my experience isn't super complete ๐Ÿ˜„

#

but that does sound like a job for wireshark/tshark, but in the past you can do something like netsh trace start capture=yes, do your packet stuff, netsh trace stop, then use this https://github.com/microsoft/etl2pcapng

GitHub

Utility that converts an .etl file containing a Windows network packet capture into .pcapng format. - GitHub - microsoft/etl2pcapng: Utility that converts an .etl file containing a Windows network ...

#

though really wireshark should just be doing it, so i'm curious as to what the problem there is, though i've never used wireshark on windows

cloud spruce
cedar forum
#

going to spin up a test bench on a windows box i have somewhere

#

hmm

#

yeah fresh install of wireshark on latest windows 10 is working fine here

#

i forgot how much UDP multicast runs over this network lol

cloud spruce
cedar forum
cloud spruce
cedar forum
#

crikey, only after a couple of minutes lol

cloud spruce
cloud spruce
cedar forum
#

wireshark does some nice graphs

cedar forum
cloud spruce
cloud spruce
cedar forum
#

all our studios are AoIP, so each microphone is an individual multicast AoIP stream, as is music, etc.

#

we moved from analog a year or two ago and AoIP ecosystem is so so nice, I can plug equipment in to any ethernet port and pick up/insert any AoIP stream I want into the network

#

the only bit of analogue we've still got is in inside our coffee table, we thought it'd be fun to hook the old studio selector up so you can see the needle graphs flicking ๐Ÿ˜„

elder cobalt
dusty shoal
#

can you help me with socket, I will send you the code: Server Code

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Socket Created")
s.bind((socket.gethostname(), 1234))
s.listen(5)
print("Socket is now listening")
while True:
    client_name, addr = s.accept()
    questions = ["Name: ", "Age: ", "Country: "]

    def send_message(message:str):
        client_name.send(bytes(message, "utf-8"))
        print(f"sent message to client: {client_name, addr}")

    for question in questions:
        send_message(question)

Client Code :

#
import socket
import time
c = socket.socket()
command = ""
c.connect((socket.gethostname(), 1234))
print("Connected successfully")
while True:
    question = c.recv(20).decode()

I expect it too well say questions one by one

drowsy nebula
#

you didn't put any statement to wait for an user input for example.

cloud spruce
elder cobalt
cloud spruce
cloud spruce
vernal smelt
#

Hey is it actually okay here if you share a project here? I don't really intend to advertise but I'm just so enthustiastic about what I create.

elder cobalt
fervent thorn
#

I have a server capable of serving multiple clients and I want to determine packet rate at which clients are sending packets to my server

#

The idea I came up with is keeping a frequency map for IP addresses of all the clients and storing the packets count for some arbitrary amount k seconds. Now after k seconds we traverse the map and see what IP addresses have more than 100*k packets, now we block these IP addresses. After every k seconds we empty the map and start again.

#

If somebody has clear idea about what I'm trying to ask and achieve through code, please DM me I need help

#

I've gone nuts trying to figure this out from last 2 days๐Ÿ˜ญ๐Ÿ˜ญ

cloud spruce
ember ledge
#

is it possible to make a permanent ip blacklist using iptables?

when my server gets attacked my iptables drop most of the malicious packets but my servers resources are overwhelmed in the start of attacks which causes issues, I was wondering if it was possible to somehow drop all traffic from a host if they've previously been -j DROP'ed?

cunning garden
#

but to permanently ban an ip, you can use a command line to drop all the traffic coming from a specific ip

ember ledge
#

thanks

ember ledge
#

really weird but im actually also having issues with the same thing

#

xD

ember ledge
#
import time
from DDPClient import DDPClient
client = DDPClient('wss://atshop.io/websocket')
client.connect()

while True:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        break```
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1129)
halcyon arrow
# ember ledge ```py import time from DDPClient import DDPClient client = DDPClient('wss://atsh...

Your website has SSL correct? You need to catch that SSL certificate in python and use it to communicate with the sever. Or in turn disable ssl on your website (this is not advised). Here is a stack overflow page with an explanation of the error. https://stackoverflow.com/questions/56719290/how-to-solve-the-handshake-failure-using-ssl-in-python

ember ledge
#

its the same website u were talkin with a guy a year ago

#

u can connect to it but not with the ddpclient module in py for some reason since it returns ssl errors

halcyon arrow
#

I am not sure about the ddpclient Iโ€™ll have a look, but usually you need to wrap the connection in some kinda ssl layer.

ember ledge
#

@halcyon arrow btw i even used the meteorclient module which is kind of based on ddpclient

halcyon arrow
#

I donโ€™t think the module u use is the problem. It a socket level issue with an ssl certificate I think you need to look into python ssl handling.

fervent thorn
#

How can I blacklist a client if I have it's IP address. I want them to not be able to send udp packets

cloud spruce
fervent thorn
#

And server is running on windows machine

cloud spruce
fervent thorn
#

I have not worked with firewall at all and rn I'm reading documentation of windows firewall with advanced security api

#

Kinda overwhelmed by the docs

#

I just need to add the ip addresses in the block list of firewall

full dust
#

that method isn't terribly scalable though, I would hate managing production ip blocklists in the windows firewall lol.

I'd at least look at hosting whatever application this is with IIS and setting up IP and Domain Restrictions there.

cloud spruce
full dust
#

IIS can't frontend a udp listener?

#

I'm not a sysadmin and primarily use nginx - not trying to start an arguement just curious

fervent thorn
jade aspen
#

Anyone have experience witih PySNMP and/or EasySNMP that can chat for a minute?

fervent thorn
#

Is that a problem?

#

Heyyyy I need a favor

#

I'm trying to fill up the fields of the rule according to my needs but I have just one machine with one ip address so I can't test things out

#

Can somebody help me figure out the desired fields

#

Dm please?

#

Will hardly take 5 minutes

fervent thorn
#

I've added an inbound rule to block udp connections on the port I'm running the server

#

But when I send packets using scapy to my server, it is still receiving it

cloud spruce
fervent thorn
cloud spruce
ember ledge
#

does sending requests count as networking?

cloud spruce
ember ledge
#

nvm i figured it out

ember ledge
#

hey guys I'm trying to learn how to get requests to access info and urllib to automate stuff on websites. I feel completely ignorant on the topic, does anyone know where should I start to learn the network tab, understand how to make requests etc.. Most of youtube videos just show how to do it but not the actual science behind it so If someone could tell me where to look would be greatly appreciated.

teal karma
#

Hey I am wondering I would like to host my website with out paying a fee for a service my current method is hosting it through a server I already have using apache2 is this the best practice for what i am doing or is there a better/safer way?

cunning garden
errant birch
#

Hello, does http proxy work when requested https link?

cloud spruce
elder cobalt
#

@cloud spruce ```python
wordlist = ["POST", "scripts", "Plugin"]

for x in wordlist:
conv2hex = x.encode("utf-8").hex()

with pydivert.WinDivert("ip.DstAddr = 147.135.137.85 && tcp.PayloadLength > 50") as w:
for packet in w:
data = bytearray(packet.payload)
if conv2hex in data.hex():
print("Condition met!")
w.send(packet)
else:
w.send(packet)


I'm trying to make some sort of a filter list where if it contains one of those words(wordlist) in data.hex() it'll print the Condition met! statement but for some reason it only works with the Plugin filter, it's not filtering out POST and scripts any idea why so?
cloud spruce
elder cobalt
#

Damn that's definitely so huge

cloud spruce
# elder cobalt Damn that's definitely so huge

everything that has to do with mocking you can ignore
that whole MockDivert class and a few more bits and pieces is just placeholders for me because i can't run pydivert as i'm not on windows (and the fact that i don't have the game)
the code that actually do the important stuff isn't really that much