I have installed iftop and it works fine on the command line now when I try and integrate it into Django, It does not give me any output at all but at the same time I am not getting an errors.
views.py
def packets(request, template="linux_path/packets.html"):
context = {}
tcp_data = subprocess.Popen(['sudo', 'iftop','-i', 'eth1'], stdout=subprocess.PIPE)
raw_packets = tcp_data.stdout.read()
groups = []
for raw_packet in raw_packets.split("\n"):
tokens = re.match("[5:5]", raw_packet)
if tokens is None:
continue
else:
packet_name, packet_length = tokens.groups()
group = {
"packet_name":packet_name,
"packet_length":packet_length
}
groups.append(groups)
return groups
HTML
{% extends "base.html" %}
{% block title %}
Packet Log
{% endblock %}
{% block content %}
<table style="width: 100%">
<thead>
<th>Name</th>
</thead>
<tbody>
<tr>
<td>{{function call here}}</td>
</tr>
</tbody>
</table>
{% endblock %}
I have also put in the correct code in the urls.py file
What happens is that the page just hangs on loading and does not move on into my packets.html page
Any idea of what I am doing wrong?
Once I get that working then I will be able to manipulate the data to the format that I want using RE.
I have even entered the sudo password into the command line when that option comes up but still the page hangs.