cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5354
Views
14
Helpful
12
Replies

Can i send UDP datagrams to a specific address/port?

hfakoor222
Spotlight
Spotlight

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?

2 Accepted Solutions

Accepted Solutions

"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.

View solution in original post

Dan Frey
Cisco Employee
Cisco Employee

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

 

View solution in original post

12 Replies 12

marce1000
Hall of Fame
Hall of Fame

 

          - UDP is IP-based , you can only send it to an IP address  , 

 M.



-- Each morning when I wake up and look into the mirror I always say ' Why am I so brilliant ? '
    When the mirror will then always repond to me with ' The only thing that exceeds your brilliance is your beauty! '

"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.

M02@rt37
VIP
VIP

hello @hfakoor222,

does your router support

ip sla and udp-echo ?

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/ipsla/configuration/xe-3s/sla-xe-3s-book/sla_udp_echo.pdf

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.

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 

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 

TCP and UDP Small Servers

On the devices. You can try to use it for code tests. You need to see on your device if it is still supported.

 

"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.

Joseph W. Doherty
Hall of Fame
Hall of Fame

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.)

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.

Dan Frey
Cisco Employee
Cisco Employee

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

 

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.

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.

I use this method it easy 
I change the UDP port as I want. 

Screenshot (497).png