Receive data array from Wifi with netcat and UDP - udp

Trying to interface a device using Wifi to receive data array.
Netcat is used and set up as
UDP_IP='abc.def.c.cde"
UDP_PORT=53
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(UDP_IP, UDP_PORT)
dataarray,addr=sock.recvfrom(1024)
When I run, I have Permission denied error at sock.bind().
This UDP_IP='abc.def.c.cde" is taken from ifconfig for wifi.
But I don't know port number exactly.
How do i know port number for Wifi interface using UDP and Netcat?

Related

SSH not working locally but is working externally after running nmap

I need to be able to SSH into a device on my network. Normally I am able to simply ssh into its local IP address.
I recently ran an nmap scan on it, and now when I try to ssh into its local IP address, I recieve the following:
kex_exchange_identification: read: Connection reset by peer
Connection reset by <IP> port 22
This network is setup in a somewhat unique way. It has one router that manages the Wi-Fi network (what my machine is connected to) which is connected to another box that also acts as the modem. IP addresses that are connected to the Wi-Fi box start with 192.168, whereas those connected to the modem box start with 10.0. The device I am trying to access is connected to the modem box.
Historically, just typing in its 10.0. local address has allowed me to ssh into it with no issue, even though my device is on the 192.168 network, and arp -a does not show it.
Checking the ssh logs of the device via journalctl -fu ssh, I can see that every failed ssh attempt is accompanied by the following message:
Connection reset by 10.0.0.96 port 49949 [preauth]
I do not recognize the IP above, and the port changes every time.
Is this some sort of anti-spam protection that was triggered by my use of nmap? I know it's not just my computer because I am unable to ssh into the device from anything else on my network.
Note that connecting to a VPN then using SSH to connect to the external IP address (which is port-forwarded properly) works, as does connecting via ssh to the machine from the machine itself (127.0.0.1)l
How can I fix this issue?

SSH Connection to STM32MP1 Avenger96 board

I am trying to configure WiFi connection on my STM32MP157 based Avneger96 board. I have follows below steps to configure:
ifconfig eth0 down
ifconfig usb0 down
Start WiFi: ifconfig wlan0 up
iw dev wlan0 scan | grep ssid -i This lists my WiFi with proper SSID.
Since WiFi network uses WPA authentication I copy wpa_supplicant.conf file and pass the SSID and passphrase
cp /etc/wpa_supplicant.conf .
wpa_passphrase [SSID] [passphrase] >> ./wpa_supplicant.conf
SSID and passphrase is inserted without quotes and brackets and SSID doesn't contain any spaces.
Now connecting to WiFi network:
wpa_supplicant -B -Dnl80211 -iwlan0 -cwpa_supplicant.conf
iw dev wlan0 link : Its shows it's connected to WiFi. And ping google.com is successful.
Doing ifconfig shows the assigned IP Address on wlan0.
Now the problem is I am not able to access device using SSH. When I do ssh root#[IP Address], I get message that connection timed out.
ssh: connect to host [IP Address] port 22: Connection timed out
I am not able to resolve this. Can someone please let me know how to resolve this?
Your help will be much appreciated.
P.S: I am booting the board with custom Linux image built from Yocto Project. My host machine is Ubuntu 20.04. I have enabled required drivers in kernel config. And I have also included "packagegroup-base-wifi" in my image recipe and "wifi" in DISTRO_FEATURES_append. I have tried with different networks but still same error.
Edit
I tried to connect with LAN cable but IP address is not assigned in this case.

Set UDP port of VLC server for RTP streaming on Windows 10

I ran into an issue when streaming a video using RTP with VLC in Windows 10.
I have 2 laptops, one for streaming a short video using RTP over UDP and another one for receiving and displaying the video stream.
My concern is that I can stream to a given destination address and port e.g. 10.0.0.140:5006 but I cannot stream from the same port of a given address e.g. 10.0.0.130:5006. The server port (one the first laptop) has to be the same as the client port.
I followed a tutorial to stream a video using RTP / MPEG Transport Stream and I checked on Wireshark but I always have the streaming source port not set to 5006 as I wanted (Instead, it opens random server ports).
I checked on the internet for an answer to this but I found nothing helpful for my problem. I also checked in VLC preferences I set RTP port to 5006 but still the same behavior...
Does anyone know how to change udp server port of VLC to stream exclusively from port 5006 ?
Thanks!
I finally found out the solution by myself.
I did not set a static UDP server port, but I redirect the packets on postrouting using Ubuntu over a Virtual Machine.
To post-redirect the packets, I opened a terminal, and followed the two following steps:
Declare the wanted UDP port number in iptables
iptables -A OUTPUT -p udp --sport 5006 --dport 5006 -j ACCEPT
Redirect output data in nat's table to the previously declared UDP port number
iptables -t nat -A POSTROUTING -o eth0 -p udp -j SNAT --to :5006
This method allows to redirect any UDP packets output to source port 5006 before sending them on the network.

Netcat will not send messages through UDP connection between Socket PDU blocks in GNU Radio Companion

I am fairly new to Linux and GNU Radio.
I am trying to use GNU Radio to process information. To pass information into GNU Radio, I was planning on using the Socket PDU blocks to pass in information through a socket. To test out the connection I placed 2 Socket PDU blocks in GNU Radio Companion and connected them together, then I used netcat to send and receive messages and files.
I was able to get the connection to work when I had both Socket PDU blocks to TCP server. The sending block was set to port 52001 and the receiving block to 52002. In one terminal I typed:
nc localhost 52002
In a second terminal I typed:
nc localhost 52001
After that, any messages I typed in the second terminal appeared in the first.
I tried to do the same thing with setting the Socket PDU blocks to UDP Server and using the commands:
nc -u localhost 52002
nc -u localhost 52001
But nothing I typed in the second terminal would appear in the first.
What am I missing here? Does netcat just not work with this kind of stuff, or am I forgetting a step? With being new to Linux, GNU Radio and network protocols, I don't even know where to start.
You'll have to go to the receiving terminal and press enter. This will send an empty UDP packet to the server and tell it about the existence of this terminal/socket.
Just
nc -u localhost 52001
doesn't do anything as UDP has no connection setup.

Using netcat to send a UDP packet without binding

I am trying to use netcat to simulate a NAT traversal protocol.
I have one instance that is listening for UDP packets on port 6666, as so:
nc -ul 6666
In another terminal window, I am trying to periodically send a UDP packet from port 6666 (to open the return path on my router. this would be in a script that repeats every 20 seconds to re-open the port)
nc -u -p6666 mypinghost.com 4444
The problem is netcat fails on this ping call with the message:
nc: bind failed: Address already in use
Which implies that the listener having bound to port 6666 is blocking another process from sending from that port, or possibly that netcat is trying to bind to 6666 to listen.
Is this just how netcat is written, or can I tickle it some way to let me send a packet without binding to the port to listen?
nc -ul 6666
Listen at UDP port 6666.
nc -u -p6666 mypinghost.com 4444
Using UDP port 6666 as the source port, send to mypinghost:4444.
nc: bind failed: Address already in use
That would be on the second netcat invocation, where 6666 is already in use by the first one.
Which implies that the listener having bound to port 6666 is blocking another process from sending from that port
Correct.
or possibly that netcat is trying to bind to 6666 to listen.
And definitely that. You told it to do that, so it did it.
What you are trying to do is impossible between two processes in the same host. Only one process can use a specific local UDP port at a time, unless you use SO_REUSEADDRESS, which netcat doesn't appear to implement.
As the other poster has suggested, the solution lies in using a single process.
I do not believe you can use netcat in that way. I would recommend writing a simple Python script that does both the sending and receiving tasks in one process. That way you can hold that port exclusively and still accomplish both tasks.