#networks
1 messages ยท Page 46 of 1
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
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)
like this?
or like this?
if its like this then
yeah
its definitely following the wrong person
๐
coz my coords are this
let me check the session_id conversion code, haven't really read it, just copied it
if I do understand this logic properly
data[1:2] will be comparing it with char of 18
are you sure the session id is at [1]?
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
yeah\
i think i have all the changes in this copy of the code: https://paste.pythondiscord.com/musecaqere
hmm looks like even using my statement in yours doesnt work
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
๐
rewriting packets can be hard when i can't experiment with it my self ๐
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
tried the new one and for some reason it's not sending print statements?
have you changed the server_port and Session_ID to be correct for the code i sent you? (since i don't know what should be there for you)
yeah did
okay changing it to this
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
it should be Z_pos there as that indicates what way the car is facing, isn't it?
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
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
Hmm adding relative distance to 0 basically means assigning the X Y and Z coords of Car B to Car A basically resulting to this
Increasing it doesn't seem like to increase the distance between them but instead be positioned to the left of the car
yeah, that should just copy the other car, but then we have a 180 degree rotation in there too
hmm so you think rotation is messing it up?
well I mean even if its without rotation it would just be this but the car is facing front
dont you think?
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
I feel like I might've found a relation between worldPosition and velocity
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
oh, the velocity is probably just like what you would get with a 3D gyroscope in a phone or other device that has them
using this modification when relative distance is at 5
3
0
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?
with relative distance = 3
with 5 that should look better
with 5
you think anything can be done with the help of this relation?
eh cant
don't think the velocity should change anything here, position and angle should be enough
is the drivers seat on the right side of the car in those cars?
if it is it would look like the middle of the car is centered on the driver and not the middle of the car
for the bmw it's left
okay, then that theory is out the window
as well as for the abarth its left
yeah its cantered for the bmw lol
i still wonder if the car position in the game is at the center of the car or the center of the driver, i hope the car or else there will be problems getting it right
hmm I feel like it might be at the center of the driver?

not sure
well lets say if its at the centre of the car
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
if I were to increase X and Z by + 1 it should move + 1 in front of XZ direction right?
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
let me check up real quick with someone who might know the game's physics
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
I feel like I've tried this before
and this was exactly the outcome
and the distance will be more then 5 since it's on the diagonal, it will be around 7.07107 for distance
wait so if I do know the drivers position in relative to the car's body that could be one way to find the center of the car?

@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?
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
Well gotta sacrifice sometimes 
But yeah for now I'm fine with it
I guess the code mentioned here should be fine or should there be any changes?
eh guess I'm done for today
i'm trying to mock things over here, but it's hard without any example data
haha, okay
to be continued then
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
guess i'll be seeing you here tomorrow, until then ๐
@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
@cloud spruce 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
I've decided to try out hispos + (hisvel * distance) it somewhat worked but it was really janky
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
@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)
your not really using that function right now if you still have this debug code in use:
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)
```to use it again switch which statement is commented out and not
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)
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
are you using this code now?
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) + Z_rel_pos)
yep
also just in case
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)
getting this error
for the second print statement
the first works fine
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()
looks like you are almost stationary, is that correct?
just moving a few meters and rotating a bit
Yeah I'm stationary at the first snip
i think i know what's wrong! ๐ก
After that I started rotating in a circle
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?
Loading the game up, took a short break but will get back to you in a bit ๐
But any idea behind why X rotation? With the return distance * math ... Function won't it just multiply my distance into cos(X_rotation)? Then add it to Car B position?
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?
X_rot is the heading of the target, so it will change all the time when the target turn left and right
distance * cos(X_rot) and distance * sin(X_rot) will give you the offset X and Z coordinates that your car need to be at in relation to the target to always be that distance in front of the target regardless of where the target is pointing around the X_rot axis
i think you will see exactly how behaves with the debug print statements on the console as you turn the target car around
hmm no luck with changing to X_rot as well
car's facing like this
oh, now i think we need to do one more change
can you paste the code you have right now for the definition of the relative_position_2d() function?
def relative_position_2d(distance: float, rad_angle: float) -> tuple[float, float]:
return distance * math.cos(rad_angle), distance * math.sin(rad_angle)```
try to just switch cos and sin
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)
looks like it ended up similar to before
could you paste your code that you have right now to https://paste.pythondiscord.com/ ?
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
ah I see, not an issue
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)
does the world coordinates and rotation that the game print out match what you see in the console debug output from the script for the "my pos(..." lines?
yeah
current world position
this is of the red bmw
this was the world position for the target car, what about your car (teleported one)?
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?
red car is the target car, the orange car is teleported
oh, then i had that totally backwards ๐ก
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
regarding this can't we just do a check where if X_rot is positive keep subtracting 1 from the target car * relative distance? and vice versa?
sure
let me start from first
i don't think that would work when the car moves around and turns on the map
position and XZ rotation of the current red car bmw
does the game also report the rotations like that?
nope need to check it through wireshark since it sends those to server
okay, but if you position the orange car what you think is about five meters in front of the red car and facing each other, what world position does the orange car report then?
orange teleported car
i mean if you have your script turned off and just drive there with the orange car and see what the orange car has as it's world position
5m in front of this should be
yeah I turned off the script and just drove there
only for rotation I enabled a separate script which just reads my rotation thats it
not manipulating it
regarding this...
okay, but in the picture it doesn't look like the orange car is positioned in front of the red car
5m in front of the red car
perfect, then i would also need the rotation reported right now from the red car, can your other script that doesn't modify the position print that value?
its this @cloud spruce
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
so, which value is the X rotation for the red car when it's positioned just as it is right now?
this is X rotation
of the red car
as it is right now
perfect, then i'll just crunch some numbers to try to work my way backwards to what we need for the calculation
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?
unfortunately no ๐ got to access the shared memory for that
alright, i'll have to try to reverse engineer how the world position coordinate system and cardinal direction and car rotation relates to each other then
would sharing you the .pdb file of the game be of any help?
don't know if i could use it on linux as i don't have windows and don't have the games exe and dll files anyways
ah yeah mb, need the executable of the game first
uhh @cloud spruce have you heard about or tried kaitai?
no, but looks really cool ๐
O well I do most of my packet decoding with the online IDE but looks like I was in for a surprise when I was checking how things were working with modded server packets
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
do you have a spec for the packet format of both the standard and the modded servers?
Yeah
could i have the url?
Sure hold on
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.
oops
https://files.catbox.moe/4y8fxv.zip @cloud spruce just drag and drop the contents to https://ide.kaitai.io/#
This is just to get you started if you ever plan on using this in the future https://doc.kaitai.io/user_guide.html
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
thanks for making me aware of Kaitai Struct, i think i'm going to find uses for it now and then ๐
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?
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
i think i solved it now, and if i'm right it was stupidly easy ๐
o what was the fix this time?
coz I just opened up a debugger for checking if I can find the direction of my car
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
yeah
found something interesting
how about this?
https://paste.pythondiscord.com/ezajegateh
trying it out will let you know in a few mins ๐
should I just
haha, the problem with not being able to run the code at all ๐
X_rel_pos, Z_rel_pos = relative_position_2d(relative_distance, to_float(X_rot) - X_rot_fix)
yeah, that is the fix for that
hmm tried it out no luck looks like it's still retaining the same old position as before?
that is so odd, same map and same position of the red target car?
aha, i think the rotation goes the other way around, try adding instead of subtracting
almost there
and in that case, that probably goes for the subtraction in line 31, might need addition there instead
replaced it with an addition
try value 0 for X_rotation_adjustment
yep looks like it
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)
I suppose you use relative_distance to define how far apart the car is?
yeah
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
perhaps rndpkt with the calculations you did won't it be possible to know where the car is facing?
it's in degrees and you can use like -1.5 or 3.2 or what you need to fine tune the relative position
like cardinal direction?
ah I see
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
kinda sucks that there's no way to know where your facing in game until you access shared memory
but does it matter to you which cardinal direction you are facing in the game, and you use that information in any way if nothing depends on it?
is there a map in the game?
in that case, is it fixed to north or does it rotate freely with the heading of the car?
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
maybe in future I might have some use for it as it would be really handy to know where I am facing
something like a compass
okay, but only as console output on the side then?
yeah
in case something breaks down
i wonder if they have done some real world modeling in the game when it comes to light direction ๐ค
iirc you could set the angle of the sun in game
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
ah nope
okey, i see
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
so far I guess the games finding the cardinal direction based on your X-axis rotation?
hmm
yes, the direction of the car that is
but if you want to translate it to real cardinal directions like N, NNE, NE, ENE, E and so on there is some more work to be done
will get back to you
@cloud spruce good news found a car in game which has an inbuilt compass
took a bit of searching around for old mods
This is from
Hmm what type of correlation tho
O
60 degrees difference
orange car
haha, nice find! ๐
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
what happens with the X_rot value when you start turning right, does it increase or decrease?
hmm let me try real quick
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?
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
i also wonder if different maps can have different rotations in regards to cardinal direction and if there is something in any network packets to indicate the map rotation in that case
or if all maps have the same rotation, i think that would make most sense
I'll load in a server with nothing but just a flat plane that should help getting things started
Hmm not sure
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?
Yeah
Basically rounding it off to 60 degrees
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
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
hmm yeah fair
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
Can anyone tell me is CCNA certificate important out there or not?
in recruitments u k
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
thank you ๐
do guys have an idea how for an program in the field of networking?
what do you mean?
the network field is huge/broad, you would need to be a little bit more specific then that
what is it you would like to do?
so i coded a litle file server (more or less a cloud) wich was a great project but only lastet for 2 days. an this hooked me really to servers. but now i dont have any idea of an project wich gets me deeper into the topic and is also fun to program
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
huh... ok thanks!
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
is east really -1.57 as the X_rot of the car?
i though it would be west that would be - ๐
Yeah
so, the X_rot is counter-clockwise then?
-90 degrees of X_rot is 90 degrees in game heading
haha, okay, that feels backwards, but okay ๐คท๐
what is X_rot from the packets in radians if you are heading as close to north as you can?
hold on
like, without any adjustments, the raw X_rot of the car in radians
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
and east is then close to -1.57?
Yeah
now i see, it's because everything is flipped around 180 degrees or 1 pi radians
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)?
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
Hmm any idea on how to implement? My rough guess is we take X_rot and add or multiply to it? @cloud spruce
try:
math.degrees(to_float(X_rot) + math.pi)
yep working perfectly!
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
also any idea how to maybe format it such that output shows Facing: {cardinal_direction}, Heading: {heading from 0-360} Then some sort of a suggestion pointing out that in-game it's -90 degrees/+90 degrees?
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 ๐
where you use struct.unpack('<f', X_rot)[0] you can do to_float(X_rot) instead to make it easier on the eyes
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
does this look clean?
sure, but does it work all 360 degrees around?
Yep ๐
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
you're welcome ๐
Oh btw have you had a look with kaitai?
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
i have, but not in this detail for that specific issue, hold on and i'll have a look
but i must again say that i really liked kaitai ๐
ah I see, I just got to know about kaitai a year or two ago but haven't really used it until now
was a breeze to setup things and start working with the packets though
with pydivert, are you allowed to:
use packet.payload[9:13] directly?
assign things directly to it like packet.payload[9:13] = X_pos?
or are you required to make it into a bytearray first?
need to assign it as a bytearray first
data = bytearray(packet.payload)
are you a 100% sure you can't even access them the other way without first making it in to a bytearray?
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
you mean manipulating the data without the bytearray?
or at least read the data when it's data from the server
Heyyy
Anybody knows a way to send files from my pc to a friend(different network) through terminal?
we both have linux
Hmm not sure but maybe something like this?
import pydivert
with pydivert.WinDivert("tcp.DstPort == 80 and tcp.PayloadLength > 0") as w:
for packet in w:
print(packet)
w.send(packet)
break
there are lots of ways, but it would require on of you to act as a server and have either a public ip address or do port forwarding in the home router of the person running the server side
i can't test you know, as i don't run windows i can't run pydivert as it's windows only, that's why you have to do all the testing for me ๐
Ah I see what exactly do you want? Maybe first starting the filter then? Should I like try see if there's a way to print out the payload of the packet?
nice. No idea yet how to do that, but I will try
@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?
Oh bruh was doing just that here
sorry didn't look through your message properly
and that works if you print X_rot?
Yes
That's how I got the compass to work
you did that without going through the bytearray?
Yep
hi what to learn here. what about networking if I may ask
nice, then we can use another pretty cool python feature to access each packet segment ๐
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
Oh damn that's pretty interesting, unfortunately need to head to bed again so cya take care
well worded
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
does anyone know how to create sftp server with python
yikes I guess I found an issue with my compass
game heading does not correspond at all
game_heading = round(math.degrees((to_float(X_rot) * -1)))
might be because of the * -1
i think we can do something about that
remember that game heading is flipped 180 degrees
yeah
so * -180?
woops
wasn't it:
game_heading = round(math.degrees(to_float(X_rot) + math.pi))
thats for a full 360
but game calculates between 180 to -180
no, math.tau = math.pi * 2 = 360 degrees in radians
real_heading = round(math.degrees((to_float(X_rot) + math.pi)))
I use this variable to show from 0 to 360
the + math.pi will make the compass go from 0 - 359 degrees instead of -180 - +180
a is there anyway to show between -180 to +180?
oh, you want the negative heading as well?
yeah
but you want it flipped so that 0 is north instead of south?
180 is north and 0 is south
here
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]```
yeah, but do you want it the other way around?
nah want it with respect to game so that's -90 which is east, 90 is west, 0 is south and 180 is north
ig I drew the diagram wrong when I was editing it
north should be up and south should be down
there
Hmm any luck? @cloud spruce maybe should I like create some conditions for + and - events?
i would probably do it in another way, and not use a hash and do the calculations directly in radians as that is what the data is originally to save some precision and cpu time not having to do the conversion from radians to degrees
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
Huh so I guess doing a comparison with radians itself and then converting them to degreea
a non-blocking socket should never block
are you on windows?
select() isn't very good on windows and the same goes for non-blocking sockets in windows if i remember correctly
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
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
ah yikes, I just made my own but will save your copy as well if any case mine breaks out
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)
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
that code will give you both the cardinal direction and degrees
degrees are simplest calculated with:
round(math.degrees((X_rot + math.pi) % math.tau))
tau is the constant of a full circle in radians, 2*pi, what would be 360 degrees
haha, it was far from yesterday we chatted, i think it's been well over a month, maybe even two
did you sort out the problems with the latency between your server and clients?
perhaps you move over to async programming instead for your software to cut down on the latency?
Haha yea i havent looked into it in a month i got a job its taking up my time
sounds like the development of that voice chat has stalled then
i think your best bet would be to convert the code to use async programming instead of threads or a select() loop if you ever get the time to continue with that project
either way, happy to see you back here ๐
Hello, I'm trying to get into socket programming.. I have trouble getting the server and client to send each other messages smoothly..
here is my code...
https://www.toptal.com/developers/hastebin/ripivezebu.properties
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
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
first of all, see: #networks message
it's about the construct socket.gethostbyname(socket.gethostname()) that you too are using
i'll continue reading your code, this just jumped out at me
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..
you probably want to do that for the client too, to make sure it connects to the same address that the server is listening on
i have checked you code now
no, you are making some assumptions that just isn't true for the socket api
the recv() function can return 1 or more bytes up to the number of bytes you have specified, it will not block and wait for data until the buffer is full
so you can't do recv(64) and expect it to always be returning 64 bytes, remember that you are reading from an unpredictable stream
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
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?
that is the thing, the socket api doesn't work like that, you only request the maximum amount of data that you want to receive
but there is no guaranties about how many bytes you will get, as soon there is data you will get the data that is available at that point in time when you call recv(max_bytes)
but you probably want a delimiter (character or string) between messages
or some fixed header, like you have attempted, but implemented in another way
this goes equally for the server and client programs of course
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?
yessir i was thinking about starting async programming as it just saves a lot of time
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
it depends on how you are writing the code: select, threads, asyncio, blocking or non-blocking io, etc
it sounds like you are using normal blocking io without asyncio, but with or without threads and are you using select()?
@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?
I think the select is the easiest method? I've read that there are other more efficient methods but some are OS dependent and basically its just harder to implement
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
and by the way, if you're on windows you have IOCP (I/O Completion Ports) which is what should be used there instead if you need performance and/or scalability, even if select() works there it's very inefficient on windows
@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
do you need any information to be transferred between clients, like a chat, shared world game server?
or is it just data to and from the server, like a web server, file server, mail server, etc?
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)?
@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
aha, then you do need multiple sockets per thread even in a threaded server, since you need one on the client side and one on the server side
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
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
as you can see there are lots of options to choose from, i think you'll like the asynchronous programming paradigm when you get the hang of it and is very well suited for your use case with the proxy server
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
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
@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
i'm on my mobile right now and without access to a computer for a few more hours
Ah no issues, just thinking if maybe you might've found a much better solution than mine lol
Mine just doesn't work ๐
hello, can i ask here somthing about netmiko and linux ?
just ask and we'll see if anyone can help
Is there anyone work as a freelancer? I wanna start a freelance career. I would appreciate it if you guys help me out.
Go and find customers who wants to buy your service. E.g. if you can design them a logo, tell them how much you charge and when it can be delivered. If they like your service, they'll probably hire you again or refer you to their contacts for new businesses.
Actually im gonna work in data science and ml besides i dont have a degree. Do they care?
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?
it will very much depend on each customer, but this discussion really belongs in #career-advice
Not sure if making fun of my question or a serious question ๐ค
starting what within networking exactly?
i would go with async io with one of the libraries that enables that instead of threads in that specific situation to handle all the connections, together with asyncpg and a connection pool towards the database
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
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)
what kind of API would your server provide to the clients to access the database (as in: sockets, REST API, websockets, etc)?
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?
sockets will not do what you want here, as you want to divert, hold/pause the matching packets and process them before you send them on their way
pydivert is using a windows facility known as windivert to accomplish this for you, linux and bsd has other facilities to accomplish similar tasks, it can't be done with just sockets
ok so how would u actually use UDP in async?
i assume you dont just slap async into the function ofcourse
@cloud spruce
So I can use this to listen to many different sockets at once?
No idea what REST API or websockets are, ect. I'm only just barely familiar with normal sockets right now
At the moment my client and server are connected via a stream/ TCP socket
ya
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
the use case was a proxy server, i it will be better to go async from the start
i haven't found the time to write some example code for you yet, working on something else right now
i dont want example code for my case i just want a generalized one
i maybe able to do it myself but i havent worked with async that much
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.
the user-agent header might yield some infomation
oh, do you know if there's a way to print out the header?
import requests
r = requests.post(API_URL)
# get request headers
print(r.request.headers)
ah, thanks
Is this code only or networking as general ? ๐ค I am trying to find someone that would help me with management switch
generally it's code for almost all channels on this server besides maybe #microcontrollers
but the topic on this channel might suggest otherwise, so try asking and we'll see if anyone can help
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?
what is the make and model of the managed switch?
mikrotik hEX
ID: RB750Gr3
are you using windows on your computer or something else?
yes windows. but i am trying to set it throu web
do you already have a ip address setup on it that you know so that you can login to it?
otherwise mikrotik has a program called winbox that you could download and use to connect to the device to manage it
when i reset it and conect to pc, i get address
so, you know the address to the switch so that you can login to it?
or do you mean that you get an address for your computer?
bouth, i am curently in the switch managmet UI (winbox )
doesn't your provider use a separate VLAN for IPTV?
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
Does anyone here have experience converting UDP from matlab to python?]
agreed, sounds very plausible
i haven't used matlab and know what matlab has to do with UDP
but that doesn't mean i won't try to help anyways if i can be of any help ๐
hey @cloud spruce, thanks for responding. I've posted my question in #help-chocolate
asyncio udp ๐
need assistance
no clue how to do
or just handling multiple clients
i dont know what i did wrong
@cloud spruce back to square one with https://github.com/e1pupper/VoiceChat
im gonna rewrite it
follow along a bit in the #help-chocolate then ๐
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
this is absolutely crazy what u just linked me
i love you !
happy to help where i can ๐
so how is it not non blocking
the idea with async programming is that you should call functions that are declared with the async key word with await (meaning "asynchronously wait")
ya dats why i was asking about it
cause i dont think this really solves the issue
but is part of the solution
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
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 ๐
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
okay before i get into async and all dat i managed to clean up the code from github
i will do some tests now
I need list pip python libraries for network analyzer
hello
should https stuff be setup in gunicorn or in nginx?
i have flask --> gunicorn --> nginx
so, i solved my Router problem. ๐ now to the code... ๐
mikrotik > RouterOS... anyone? ๐
what/which network analyzer are you talking about?
i would defensively configure the TLS termination in nginx
and if that is on another machine or even container and you need higher/stronger security you would need to encrypt it again and run TLS between nginx and gunicorn (which runs your flask app directly)
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
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
ok
have u heard of cyberpanel before @cloud spruce
no, why?
is it like cPanel?
not sure but i just started using it to make a mail server
pretty handy
okay, when i checked their website (if it's even the same thing as you are talking about) it looked like it was mostly hosting for wordpress and php (which i'm really not a fan of)
what is?
cyberpanel
@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
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
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
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
which OS (and version) are you running it on?
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
Ah I see, yeah I don't really rely on kaitai's python parser only use it for knowing where to splice
I took your implementation and tried changing it in a way that offsets get multiplied by a counter * 60
or, well. not always the slowest, but for the modded server it was really slow as it always decodes everything from all instances
o I see
i wanted to try it out as i have never used it in python before ๐
I guess it'll be useful for small projects
or places where you don't need to decode stuff very rapidly
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
it helped me for decoding packets ngl, but didn't really find any use for using it on python since the bytes were enough alone to do comparing and etc...
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?
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
In theory this sounds so simple and logical but in reality it's taking me over a week lol
well, it would have been quicker if i have had more time to dedicate to this
yeah that's what I'm afraid it is, sometimes I like to think that's not the case until someone points it out lol
no issues lol, understand you were busy throughout the weekend
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
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
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
iโm good with radios
If you want asynchronous networking you can use asyncio
It's not as low level as socket though
is there some stron boy from networks in debian?
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
you should be able to bind to the UDP port in one place in your script and then reuse that socket object everywhere as you see fit, or you can pass the socket object/variable into the methods
@cloud spruce any luck?
or maybe any idea where I could start?
raw_data, addr = conn.recvfrom(65535) # Conn receives from '65535'
OSError: [WinError 10022] An invalid argument was supplied
Is your socket bound?
?
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
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
Manually?
How did you make the socket?
Can you make a run-able example?
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
Try a breakpoint at the line that fails?
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
raw_data, addr = conn.recvfrom(65535) # 'Conn' receives from '65535'
OSError: [WinError 10022] An invalid argument was supplied
just before the inner async with print self.url and see if it contains what you expect it to
Ye it does
What does it look like with the breakpoint there?
Does it work with httpx?
i have a meeting but ill tell you after
can someone help me with a slow loris ddos attack
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
are you under attack and need help protecting your self from it?
otherwise: no, see above rule
No i got oermission from my friend to try take down his website
Permission
Iam not breaking any laws
no difference, we can't know if you are telling the truth or if you are going to reuse it later for something else
so, the rules still apply
Thats true
Ima go
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
like input()?
you freak me out lol
yes
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)
packet_counter is pretty self explanatory, but does it count all packets in both directions in one counter?
and what is counter counting exactly?
not sure what you meant by both directions, but it sends a batch of SessionIDs included with their information like position, rotation and etc. in one single UDP packet to me (the client) from server
this is so far my latest modification
I'm using counter to iterate everything being received from the server
like every byte being received
oh, i first thought packet_counter what the number of network packets that you have processed
but is it rather the number of updates contained in the packet?
correct
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
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
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
sounds like a debian based distro, but for people to be able to help you easier it's good to announce which distro and version you are running
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
Ah no issues looking forward to it
Also glad you found the .bin files useful I should've provided them from the start lol
@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
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
https://paste.pythondiscord.com/usumejabem made a new one
Really frustrating ngl, thought this could've worked but nope
Does their exist anything like the BytesAvailableFcn for python?
ref: https://www.mathworks.com/help/instrument/bytesavailablefcn.html
You configure BytesAvailableFcn to execute a callback function when a bytes-available event occurs.
Does anyone have experience defining a udp socket using asyncio
yes, and I think asyncio or other async framework/library will be your best bet as it's event based
do you have any examples?
we can continue in there ๐
but didn't understand what you wanted to do exactly
do you want to setup a firewall?
https://docs.python.org/3/library/asyncio-protocol.html#udp-echo-server
maybe not the best, but at least something and it's part of the asyncio documentation
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)
sure, you can use iprables for that by setting up logging and rate-limit or blocking connections from a specific host
i think in here or in #unix or maybe #cybersecurity are good places for that question
lets say a collection of random ips send the data, then what? the rate-limiting is useless then.. but thanks
yes, or ip spoofed packets, then you need DDoS protection services
from your previous question I thought that you knew the ip addresses that you wanted to act on
i mean, i do.. i discovered the vuln and exploited it on my own servers but i cant fix it :P
if you know anyone or any articles that could possibly help that would be awesome, thanks
sorry, but i fail to see the vulnerability other then the classic DDoS vector where someone trys to exhaust your bandwidth by filling your uplink with unsolicited traffic, or am i missing anything here?
can i show you what im doing? i think it would be alot better to see what im talking about
sure, but show me how, screenshot?
a detailed description or through explanation is often helpful
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
im not well educated on networking terms, i hope you get what i mean by packet data
im just trying to track this... somehow...
do you mean payload?
yeah my bad
what I don't understand is what you mean by "track", is it just to keep track of or to trace it to its source?
like, able to control... rate-limit or drop.. etc...
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
well ugh, this bypasses ovh, path, 100up... etc, the list goes on so i might just be in a pickle...
thank you for your time
Any easy way to calculate time taken to send certain mb of data between 2 cities?
no, it will depend on available bandwidth of the whole network path between the two and possible congestion which can fluctuate wildly during the time of the transfer, the best you can do is try to observe the throughput and calculate it based on that
unfortunately a very common problem ๐
I dont need exact timings. Just approx. I found https://wondernetwork.com/pings . Will this be any useful?
I mean will ping stats be approx same as sending even 1kb/1mb/1gb/1tb of data proportionately?
no, and you would need to measure the data transfer rate between the two clients specifically
Hello I am having this error in socket.io
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?
i'm trying to think of something, but this isn't really a networking issue
just converting numbers from one base to another
oh so the base of the numbers are different?
this is in hex, isn't it?
oh yes yes i converted it into bytes because that is the only way to send from client to server and vice versa
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
i'm aware, i'm trying to see how to convert that back to its
oh wait i already converted it into int
age = int(input("Age: ")) , it is converted to int already
you want something like int.from_bytes(mystr.encode('utf-8'), 'big'), maybe? though idk which endiannness you used
i'm not sure about the part where you do bytes(age) though
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?
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?
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)
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 ๐)
@cloud spruce Thanks for the suggestion and code!
you won't know other then by trail and error, it depends a lot on the server and the code running there as well as configuration of the same
another suggestion would be to send the questions from the server instead of having them hard coded in the client software
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 ?
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
also how can i send inputs to the user as send?
and yes I hereby confirm that I am total moron
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
just loop in the client as well
so a for loop in the while true loop in the client and a for loop in the client am i right?
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()
anybody here?
yep
or i guess received
right now im using netstat -sp udp
but i want to specify one 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
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
i have this condition satisfied
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
yeah, you would have to count the packets with your program rather then with netstat
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
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
ah, i see, then you probably need to break out a packet capture program, also called a sniffer, that you can run if you have superuser privileges
that's fine, as long as you are admin on your computer you can install and run wireshark on it
i don't know windows well enough to know if there is some special facility that you would be able to use for this on that platform
I need something either in code, in a terminal, or cli
No worries Iโll keep Searching around online
why not an application like wireshark?
wireshark comes with tshark, it's more or less the same thing for the cli (in both windows, linux and mac)
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?
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
right now i'm looking in to why i sometimes get an error that i need to take care of
Canโt display
i haven't really used tcpdump on windows and don't know if it's any good
as @main spruce is on windows if i understand it right
that seems unusual if your on windows
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
sounds like you know windows a whole lot better then i do
all @main spruce wants to do is to count udp packets that matches one single port to debug why the application isn't receiving any packets on the port that it's listening to
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
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
haha, i've only used wireshark (gui) and tshark (cli) for that on windows
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
interesting, i've never used or even knew about netsh trace
i'm happy to learn of its existence if i need it for troubleshooting in the future ๐
yeah, it's been nice to use in the past, mainly because it means I don't need to install stuff on the remote
yeah, i've been using wireshark/tshark [even on windows] for years and it works really well
crikey, only after a couple of minutes lol
yeah, that's a very good point, just transfer the file to another system and convert it to pcap format and run it there โ
haha, must be updates ๐
wireshark does some nice graphs
radio station, so just a whole lot of multicast audio streams ๐
yeah, love wireshark
oh, i see ๐ก ๐ป
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 ๐
Ah I see, sorta surprised tho that it's this hard ๐ normally decoding the stock server packets was a breeze but this seems to be a lot more problematic
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
you didn't put any statement to wait for an user input for example.
well, my problems was with a few other things when i refactored the code a lot without being able to test it, but now i've built the mocking and are able to test the code at last
yeah, atleast it's a bit easier now than just guessing
yeah, a lot i would say
i just hope that the mocking part of the code actually is accurate enough to emulate the parts of pydivertthat i need it to emulate
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.
I can send you in more lol if you want to refine it a bit more
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๐ญ๐ญ
last i checked this server and channel has more to do with python then c++ ๐
here are three different techniques for rate limiting implemented in python: https://dev.to/satrobit/rate-limiting-using-the-sliding-window-algorithm-5fjn
but if you know both python and c++ to can probably transfer the general techniques to between the languages
and there is even more of them if you just google for "rate limiting algorithm" and go from there
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?
you may be interested in fail2ban
but to permanently ban an ip, you can use a command line to drop all the traffic coming from a specific ip
i was away from my pc when you responded, i think this is what im looking for
thanks
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)
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
I try connect to specific https server:
socketHandler = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socketWraped = ssl.wrap_socket(socketHandler)
socketWraped.connect(('certificatedetails.co...
it's not mine, but it has ssl
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
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.
alr
@halcyon arrow btw i even used the meteorclient module which is kind of based on ddpclient
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.
How can I blacklist a client if I have it's IP address. I want them to not be able to send udp packets
they will still be able to send them, it's you who will be blocking them so that you don't receive the packets
what OS does the machine have that you want to block packets to?
I mean yeah, I might have framed my query wrong but all I want is to not receive their packets at my server.
And server is running on windows machine
oh, i don't know windows that well, but i believe you should be able to set up the windows firewall to block certain ip addresses
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
you should be able to do it with a powershell one-liner:
Net-NewFirewallRule -DisplayName "Block IPv4 Ingress" - Direction Inbound -Action Block -RemoteAddress X.X.X.X
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.
not applicable as @fervent thorn wanted to block udp packets to the server, i'm assuming the application is listening on an udp port and isn't performant enough to take care of the filtering it self
IIS can't frontend a udp listener?
I'm not a sysadmin and primarily use nginx - not trying to start an arguement just curious
Well I'm going through the documentation on msdn and am trying to achieve this kinda thing by their api programmatically
Anyone have experience witih PySNMP and/or EasySNMP that can chat for a minute?
Yes my server socket is a raw socket listening listening to mainly udp packets
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
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
you said you are using raw sockets, that usually means it's the same as setting up a sniffer, which will see traffic before the firewall can block it
your options are either to not use raw sockets and just bind to one or more udp ports that you are interested in or filter the traffic in a physical firewall or server in front of your server running the program
On what layer does the firewall work?
just above the raw socket layer, raw sockets bypass all such things
it's even required for packet capture/sniffer applications like wireshark to work as expected/designed
does sending requests count as networking?
i guess... ask your question and we'll see if anyone answers
nvm i figured it out
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.
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?
gitlab/github pages are good options
Hello, does http proxy work when requested https link?
yes, if your client and proxy server can handle the connect method (most can) used to proxy https or any ssl/tls over a http proxy
@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?
i'll check out your new code later today
i've just finished with https://paste.pythondiscord.com/ugojunedep for you
much more then half of the code is just for debugging (if/when needed) and/or mocking, i left it all in there
run the script with the -h or --help options to see how to start it
as an example run it with the options -s <server-ip> -p <server-port> -i >session-id>
Oh holy shit thanks alot
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