Changeset 906:0c387ff526c8
- Timestamp:
- 09/12/08 14:02:11
(4 months ago)
- Author:
- Phil <phil@secdev.org>
- Message:
Fixed netstat -rn output parsing on Solaris (ticket #135)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r885 |
r906 |
|
| 7 | 7 | import sys,os,struct,socket,time |
|---|
| 8 | 8 | from fcntl import ioctl |
|---|
| | 9 | from scapy.error import warning |
|---|
| 9 | 10 | import scapy.config |
|---|
| 10 | 11 | import scapy.utils |
|---|
| … | … | |
| 34 | 35 | mtu_present = False |
|---|
| 35 | 36 | routes = [] |
|---|
| | 37 | pending_if = [] |
|---|
| 36 | 38 | for l in f.readlines(): |
|---|
| 37 | 39 | if not l: |
|---|
| … | … | |
| 50 | 52 | break |
|---|
| 51 | 53 | if scapy.arch.SOLARIS: |
|---|
| 52 | | dest,mask,gw,netif,mxfrg,rtt,ref,flg = l.split()[:8] |
|---|
| | 54 | lspl = l.split() |
|---|
| | 55 | if len(lspl) == 10: |
|---|
| | 56 | dest,mask,gw,netif,mxfrg,rtt,ref,flg = lspl[:8] |
|---|
| | 57 | else: # missing interface |
|---|
| | 58 | dest,mask,gw,mxfrg,rtt,ref,flg = lspl[:7] |
|---|
| | 59 | netif=None |
|---|
| 53 | 60 | else: |
|---|
| 54 | 61 | if mtu_present: |
|---|
| … | … | |
| 73 | 80 | if not "G" in flg: |
|---|
| 74 | 81 | gw = '0.0.0.0' |
|---|
| 75 | | ifaddr = scapy.arch.get_if_addr(netif) |
|---|
| 76 | | routes.append((dest,netmask,gw,netif,ifaddr)) |
|---|
| | 82 | if netif is not None: |
|---|
| | 83 | ifaddr = scapy.arch.get_if_addr(netif) |
|---|
| | 84 | routes.append((dest,netmask,gw,netif,ifaddr)) |
|---|
| | 85 | else: |
|---|
| | 86 | pending_if.append((dest,netmask,gw)) |
|---|
| 77 | 87 | f.close() |
|---|
| | 88 | |
|---|
| | 89 | # On Solaris, netstat does not provide output interfaces for some routes |
|---|
| | 90 | # We need to parse completely the routing table to route their gw and |
|---|
| | 91 | # know their output interface |
|---|
| | 92 | for dest,netmask,gw in pending_if: |
|---|
| | 93 | gw_l = scapy.utils.atol(gw) |
|---|
| | 94 | max_rtmask,gw_if,gw_if_addr, = 0,None,None |
|---|
| | 95 | for rtdst,rtmask,_,rtif,rtaddr in routes[:]: |
|---|
| | 96 | if gw_l & rtmask == rtdst: |
|---|
| | 97 | if rtmask >= max_rtmask: |
|---|
| | 98 | max_rtmask = rtmask |
|---|
| | 99 | gw_if = rtif |
|---|
| | 100 | gw_if_addr = rtaddr |
|---|
| | 101 | if gw_if: |
|---|
| | 102 | routes.append((dest,netmask,gw,gw_if,gw_if_addr)) |
|---|
| | 103 | else: |
|---|
| | 104 | warning("Did not find output interface to reach gateway %s" % gw) |
|---|
| | 105 | |
|---|
| 78 | 106 | return routes |
|---|
| 79 | 107 | |
|---|