How to send UDP/TCP packet to ESP32 using win10 command line - Page 1
Forum section: electronics / general

author: Psi
author_rank: Super Contributor
timestamp: February 08, 2018, 09:38:30 pm
content: I have an ESP32 wifi module setup to control some relays at my work but i need to be able to send it a message over wifi from the local LAN to tell it which relay to turn on/off.For reasons i don't want to go into I can't download, install or create any app on the work machine to send a network packet to the esp32.So what i'm after is any toolincludedwith default win10 installs that can send a UDP/TCP packet to a given IP address (or MAC).I though of using ping and changing the TTL byte to carry my data however ping is ICMP and it's not easy to get at the ICMP layer on ESP32 without putting it into promiscuous mode which is complicated. (unless someone knows an easy way to detect ICMP packets on esp32 ?)Can anyone think of acommand linewin10 tool that i can use to send a TCP/UDP packet with a parameter i can abuse to carry my data?It really doesn't matter what the packet is, as long as its on TCP or UDP on a particular port then i can grab the packet on ESP32 no problem.Before you ask, yes i have permission to add the esp32 to the wifi network.

author: Yansi
author_rank: Super Contributor
timestamp: February 08, 2018, 09:42:16 pm
content: Typetelnetin the command line.That way you can make a bidirectional TCP connection.After all, you can use WireShark to mess with a network.

author: Psi
author_rank: Super Contributor
timestamp: February 08, 2018, 10:03:31 pm
content: Can you script telnet to send a packet in a batch file though?I wonder if a powershell script might be the best way to do this.

author: Yansi
author_rank: Super Contributor
timestamp: February 08, 2018, 10:08:28 pm
content: Best way is to write your own application. Handling simple ethernet communication is not that complicated. After all, you can program ESP32, why not the PC?

author: cv007
author_rank: Frequent Contributor
timestamp: February 08, 2018, 10:13:07 pm
content: http://www.powershellmagazine.com/2014/10/03/building-netcat-with-powershell/I have not used powershell much, but that is where the power is (hence 'power'shell, I guess).Probably time to learn powershell, and forget the last 20 years of batch file knowledge

author: Avacee
author_rank: Unknown
timestamp: February 08, 2018, 10:54:17 pm
content: You can do this directly in Powershell (assuming you have permissions):http://www.leeholmes.com/blog/2009/10/28/scripting-network-tcp-connections-in-powershell/http://pshscripts.blogspot.co.uk/2008/12/send-udpdatagramps1.html//Read the comments for the full source to Copy+Paste as there's an image over the last few lines of sample codeEdit: I tested this UDP one and the packet shows up in wireshark on both sender and target

author: Psi
author_rank: Super Contributor
timestamp: February 08, 2018, 10:59:18 pm
content: Quote from: Yansi on February 08, 2018, 10:08:28 pmdid you not read the original post?

author: Psi
author_rank: Super Contributor
timestamp: February 08, 2018, 10:59:53 pm
content: Quote from: Avacee on February 08, 2018, 10:54:17 pmawesome

author: jonnyb
author_rank: Newbie
timestamp: February 09, 2018, 12:18:21 am
content: There's a simpler way still using powershell...$server = 'the_server_name_or_ipaddress'$port = 1234$message = 'the message'$client = New-Object System.Net.Sockets.UdpClient$client.Connect($server, $port)$bytes = [System.Text.Encoding]::ASCII.GetBytes($message)$client.Send($bytes, $bytes.Length) | Out-Null$client.Close()

author: westfw
author_rank: Super Contributor
timestamp: February 09, 2018, 02:07:17 am
content: QuoteThat juxtaposition of statements is particularly ... troubling.

author: Psi
author_rank: Super Contributor
timestamp: February 09, 2018, 05:35:12 am
content: I found a easier wayMicrosoft tool portqry.exeIt requires installing. But is a tool from Microsoft so pretty safe.I'll just have use the incoming port number on the esp to convey the data

author: Jeroen3
author_rank: Super Contributor
timestamp: February 09, 2018, 06:41:32 am
content: Quote from: Psi on February 08, 2018, 09:38:30 pmInternet Explorer.

author: cv007
author_rank: Frequent Contributor
timestamp: February 09, 2018, 07:55:03 am
content: QuoteQuoteQuoteWritten 14 years ago. I'm sure its safe, its only a port scanner, and its from Microsoft. The network admin at work won't mind having a port scanner on the network either- you are good to go.QuoteThat makes more sense.

author: Psi
author_rank: Super Contributor
timestamp: February 09, 2018, 08:29:41 am
content: haha, you mean call internet explorer from a batch file trying to browes to a webpage on the esp32 host/port.That would probably work, but i will stick with portqry

author: Jeroen3
author_rank: Super Contributor
timestamp: February 09, 2018, 08:59:57 am
content: You could make it as simple as an FTP request, that's also built-in and doesn't open a window.

author: GeorgeOfTheJungle
author_rank: Super Contributor
timestamp: February 09, 2018, 10:04:48 am
content: http://esp32ip:port/relay/1/on