Different UDP source ports while using python subprocess

650 views Asked by At

I'm using Python subprocess module to call "iperf" command. Then I parse the output and get the source port of the iperf client, e.g. 4321 but when I monitor the network 4321 is missing and I can only see UDP ports 12851 and 0. It is strange that when I call iperf command directly from Ubuntu terminal I can see the source port that iperf reports (4321) in the network. Can anybody help me and explain why this change of port happening? And how I can enforce subprocess to send the data on the original port that iperf sends?

This is how I call iperf and obtain the source port:

import subprocess, sys, os
cmd = "iperf -c %s -p %s -u -b %sm -t 10 -l 1500" %(self.ip,self.port,self.bw)
print cmd
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
o_list = output.split(']')
o_list = o_list[1].split(' ')
for i in range(len(o_list)):
  if o_list[i] == "port":
    self.my_port = int(o_list[i+1])
    break
    #endIf

And I use same command In terminal and get different output:

iperf -c 10.1.1.2 -p 5001 -u -b 10m -t 10 -l 1500

I'm doing a project in Software-Defined Networking area and using POX as network controller, so I can easily monitor desired packets (here UDP packets) and their source and destination ports. This is the code that I added to forwarding.l2_learning to monitor UDP ports:

if msg.match.dl_type == 0x0800:
  if msg.match.nw_proto == 17:
    log.warning("FOUND UDP" + str(msg.match.tp_src))

Thank you in advance

0

There are 0 answers