OpenWrt Forum Archive

Topic: View Connections FROM Router?

The content of this topic has been archived on 14 Aug 2014. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I just updated to RC5 and noticed the new Connections page in Webif. It kind of reminded me of a page that some ACTIONTEC combo Router/DSL-Modems have that would show the url of any connection on the router (websites users were visiting, etc). I wanted to emulate this function and add it the connections.sh on my router.

However, I can only get netstat to list the local addresses, and the /proc/net files only seem to contain hex coded local addresses as well. I thought I could maybe use IP tables to log all traffic to a file on /tmp and then tail that file and parse the outputs.

The reason I'm posting is
1) I don't know how to do that with ip tables.
2) that log file is going to get pretty big pretty fast. I could use a cron to delete it periodically, but that seems like a poor solution, too.

Anyone know how to setup 1, or have any ideas about 2? Or, better yet, know of a more direct approach? Tinyproxy looked like another option for 1, perhaps, but the download site in the wiki is down...

Do this:

#ipkg install http://tornado.stormchasers.dk/openwrt/netstat-nat_1.4.3_mipsel.ipk

And create a file to monitor activity with webif..

/www/cgi-bin/webif/natconnections.sh:

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "NAT Connections" "@TR<<NATted Connections>>"
?>
<table style="width: 90%; text-align: left;" border="0" cellpadding="2" cellspacing="2" align="center">
<tbody>
        <tr>
                <th><b>@TR<<Router Connections|Connections trough the Router>></b></th>
        </tr>
        <tr>
                <td><pre><? netstat-nat 2>&- | awk '$0 ~ /^Active UNIX/ {ignore = 1}; ignore != 1 { print $0 }' ?></pre></td>
        </tr>
</tbody>
</table>

<? footer ?>
<!--
##WEBIF:name:Status:1:NAT Connections
-->

If you don't want it to resolve names on ip lookups, you can change netstat to this:

netstat-nat -n 2>&-

instead of

netstat-nat 2>&-

, don't touch rest of that row smile I'm just so lazy that I didn't type rest of the line (and didn't reach mouse because it was so far away, so cutting and pasting didn't happen;)

I also have changed my normal connection page (connection.sh), I removed -n from there so it resolves hostnames now, I like it more that way smile

Actually I would strongly advice to use -n option big_smile

I opened msn messenger and used ntp-date to acquire time and date from ntp.pool.org while starting to connect to 2 web pages and opening that page took forever by that moment big_smile

So, yes, add -n smile

---

netstat-nat should be in normal repositories..

Netstat-net doesn't seem to resolve names anyway. In fact, I tried using nslookup, but it seems the one on the router can only resolve names to ips and not the reverse. That's kinda too bad..

Thanks for doing the leg work for me jake!

I have small changes to suggested WEBIF script:
- by default the script calls “netstat-nat –n”
- added link “Get DNS names” that allow you to resolve DNS names of IP addresses.

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "NAT Connections" "@TR<<NATted Connections>>"
?>
<table style="width: 90%; text-align: left;" border="0" cellpadding="2" cellspacing="2" align="center">
  <tbody>
    <tr>
      <th><b>@TR<<Router Connections|Connections trough the Router>></b></th>
    </tr>
    <tr><td><?echo $1?></td></tr>
    <tr>
      <td><pre><?
      if [ "$FORM_action" = "dns" ]; then
         netstat-nat 2>&- | awk '$0 ~ /^Active UNIX/ {ignore = 1}; ignore != 1 { print $0 }'
      else
         netstat-nat -n 2>&- | awk '$0 ~ /^Active UNIX/ {ignore = 1}; ignore != 1 { print $0 }'
      fi
      ?></pre></td>
    </tr>
  </tbody>
</table>
<p style="position: absolute; right: 1em; top: 10.5em"><a href="natconnections.sh?action=dns">@TR<<Get DNS names>></a></p>
<? footer ?>
<!--
##WEBIF:name:Status:1:NAT Connections
-->
vidlar wrote:

please help I don't download netstat-nat_1.4.3_mipsel.ipk from http://tornado.stormchasers.dk/openwrt

I'm not sure what you're asking. The file appears to still be there. Did you try using "ipkg install" to download and install it like jake showed in the 3rd post? What errors or messages are you getting when you try?

The discussion might have continued from here.