05-23-2023
06:37 PM
- last edited on
05-30-2023
12:10 PM
by
Translator
I'm trying
UDP x.x.x.x x
in a lab environment and the router is trying to open a connection to the other end. Is there a way to send a UDP packet to a specified address and port? What i would actually like to do is send a message to a port on my local computer, since ping can't do that I tried the UDP command, after specifying UDP out in the line configurations, and so now its trying to establish a connection. I'm guessing it's doing that because computers typically use ports to establish connections, and so that's what cisco built in.
I'm trying to run a python script based off of a UDP/port ping, since doing it via ICMP to a specific address requires more knowledge than I have at the moment.
Any ideas?
Solved! Go to Solution.
05-24-2023 03:00 AM - edited 05-24-2023 03:25 AM
"UDP is IP-based , you can only send it to an IP address , "
The UDP protocol does support using ports. Possibly what @marce1000 is saying is that a particular UDP command/app doesn't support providing port numbers.
05-24-2023 10:42 AM
I have sent UDP packets using tcl shell on the router.
Router:
INET#tclsh
INET(tcl)#package require udp
1.0
INET(tcl)#set sock [udp_open]
sock0
INET(tcl)#fconfigure $sock -remote [list 192.168.0.28 12346]
INET(tcl)#puts -nonewline $sock "Hello from IOS"
INET(tcl)#flush $sock
Host
[root@CrashCart nmea]# ./tcl_udp_server.tcl
Listening on udp port: 12346
13:40:41.525124736 192.168.0.20 53298: 14 Hello from IOS
The host is running this code for UDP server.
[root@CrashCart nmea]# more tcl_udp_server.tcl
#!/usr/bin/tclsh
# A simple UDP server
package require udp
proc udpEventHandler {sock} {
set pkt [read $sock]
set peer [fconfigure $sock -peer]
set dat [exec date +%H:%M:%S.%N]
puts "$dat $peer: [string length $pkt] $pkt"
return
}
proc udp_listen {port} {
set srv [udp_open $port]
# fconfigure $srv -buffering none -blocking 0 -translation binary
# fconfigure $srv -buffering none -encoding binary
fileevent $srv readable [list ::udpEventHandler $srv]
puts "Listening on udp port: [fconfigure $srv -myport]"
return $srv
}
set sock [udp_listen 12346]
vwait forever
05-23-2023 11:44 PM
- UDP is IP-based , you can only send it to an IP address ,
M.
05-24-2023 03:00 AM - edited 05-24-2023 03:25 AM
"UDP is IP-based , you can only send it to an IP address , "
The UDP protocol does support using ports. Possibly what @marce1000 is saying is that a particular UDP command/app doesn't support providing port numbers.
05-24-2023
12:25 AM
- last edited on
05-30-2023
11:58 AM
by
Translator
hello @hfakoor222,
does your router support
ip sla and udp-echo ?
05-24-2023
01:34 AM
- last edited on
05-30-2023
11:59 AM
by
Translator
I use
ip sla udp
for generate udp traffic between two router.
You can disable control and specify the udp port you want.
NOTE:- use router as PC
(no ip routing and ip default-gateway)
and config IP UDP SLA router
05-24-2023 02:31 AM
Hi
UDP protocol does not stablish connection. UDP is connectionless protocol. Only TCP stablish connection by doing the four way handshake.
You can not just send a message to a PC by usign a random UDP port. There might be a service listening on the port. For example, you can enable telnet on your PC and them you can stablish telnet sesseion from the router to PC because, now, the PC is listening on TCP port 23
That being said, cisco used to have
On the devices. You can try to use it for code tests. You need to see on your device if it is still supported.
05-24-2023 08:30 AM
"Only TCP stablish connection by doing the four way handshake. "
BTW, TCP uses a 3 way handshake to establish a connection, but it does use a 4 way handshake to close a connection.
05-24-2023 08:26 AM - edited 05-24-2023 11:13 AM
Could you reference the lab platform, and its documentation for using the UDP command? (I'm unfamiliar with this "command", and only found a Cisco TCL reference for one.)
05-28-2023
03:20 PM
- last edited on
05-30-2023
12:03 PM
by
Translator
Sorry, it's udptn which i figured it was a telnet command applied to the vty line, I'm assuming, and after reading, via UDP. i read it was more prevalant back in the day. My basic use case was sending a UDP datagram to IP and port to trigger a Python script. Then I stuck with an ICMP ping and stripped the headers for source address. I'd still prefer a port to send datagrams too as it is less cumbersome in my opinion - imagine setting up a loopback on my local pc for certain types of pings. Or having the script filter for IP addresses and making sure it wasn't nat'ed, or if it was to adjust for the change.... and so on. I figured UDP datagrams to a port was a lot more concise and easier to implement, something which I didn't find my IOS images capable of. I read that tcl scripting was able to do this however - and now to learn tcl scripting to send UDP? I decided to change the Python script in the end.
Also the IOS devices can send data patterns. So i decided a source address and certain data pattern should suffice - on my PC loopback obviously there isn't much traffic. Implementing this in a production environment it would've felt more stable having a port. It's a passive listening script which listens for a trigger - in this case a ping via an eem applet after an interface traffic treshold. It then iterates to all connected upstream routers via
sh arp
if a certain traffic threshold incoming traffic, and keeps going, via a simple recursive function. Essentially I get a snapshot of traffic in the network.
One last point, if anyone is interested, you can connect to all ports (connect to port 0), and filter for only ICMP using traditional socket programming. It took about 2 days of researching posting and hitting my head against a wall to get that part to work, but that's why i was initially looking for a UDP ping, and switched to ICMP.
05-24-2023 10:42 AM
I have sent UDP packets using tcl shell on the router.
Router:
INET#tclsh
INET(tcl)#package require udp
1.0
INET(tcl)#set sock [udp_open]
sock0
INET(tcl)#fconfigure $sock -remote [list 192.168.0.28 12346]
INET(tcl)#puts -nonewline $sock "Hello from IOS"
INET(tcl)#flush $sock
Host
[root@CrashCart nmea]# ./tcl_udp_server.tcl
Listening on udp port: 12346
13:40:41.525124736 192.168.0.20 53298: 14 Hello from IOS
The host is running this code for UDP server.
[root@CrashCart nmea]# more tcl_udp_server.tcl
#!/usr/bin/tclsh
# A simple UDP server
package require udp
proc udpEventHandler {sock} {
set pkt [read $sock]
set peer [fconfigure $sock -peer]
set dat [exec date +%H:%M:%S.%N]
puts "$dat $peer: [string length $pkt] $pkt"
return
}
proc udp_listen {port} {
set srv [udp_open $port]
# fconfigure $srv -buffering none -blocking 0 -translation binary
# fconfigure $srv -buffering none -encoding binary
fileevent $srv readable [list ::udpEventHandler $srv]
puts "Listening on udp port: [fconfigure $srv -myport]"
return $srv
}
set sock [udp_listen 12346]
vwait forever
05-28-2023 03:22 PM
that actually looks pretty cool. I read up on some blogs about tcl UDP scripts. Thanks for the reply I will keep it in mind.
05-28-2023
03:39 PM
- last edited on
05-30-2023
12:09 PM
by
Translator
I use simple
ip sla udp
echo generate any udp ports I want.
But I think you missing get my point.
Use router as pc.
There is other option I dont like it'
https://howdoesinternetwork.com/2015/how-to-generate-network-packets
This appliance you can add to gns3 generate udp traffic but I dont like it.
Anyway check it.
05-29-2023 06:29 AM
I use this method it easy
I change the UDP port as I want.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide