Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
routen reittien poisteleminen
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Finnish
View previous topic :: View next topic  
Author Message
Obi-Lan
Apprentice
Apprentice


Joined: 21 Jan 2005
Posts: 230
Location: Riihimäki

PostPosted: Fri Nov 03, 2006 3:07 pm    Post subject: routen reittien poisteleminen Reply with quote

Voiko millään komennolla poistaa kaikki esim. tiettyyn verkkokorttiin liittyvät routet kerralla? Tai skriptillä?
Back to top
View user's profile Send private message
Shopro
l33t
l33t


Joined: 12 May 2004
Posts: 678
Location: Dayton, OH, USA

PostPosted: Fri Nov 03, 2006 8:45 pm    Post subject: Reply with quote

Mitä haet takaa sillä? Ihan vaan mielenkiinnosta.
_________________
Just because I have nothing to say is no reason why you shouldn't listen.
Back to top
View user's profile Send private message
Obi-Lan
Apprentice
Apprentice


Joined: 21 Jan 2005
Posts: 230
Location: Riihimäki

PostPosted: Sat Nov 04, 2006 12:26 pm    Post subject: Reply with quote

Tarkoitus olisi väsää skripti joka poistaa kaikki wan kortin routet, lisää yhden uuden routen, avaa pptp (ppp0) tunnelin ja routtaa kaiken liikenteen sen kautta. Olen saanut tämän toimimaan pptpconfigilla, mutta tahtoisin duunaa skriptin mikä hoitaa kaiken kerralla, esim. jos tarvitsee kone bootata yms.
Back to top
View user's profile Send private message
jroo
n00b
n00b


Joined: 06 Mar 2005
Posts: 52
Location: Finland

PostPosted: Sat Nov 04, 2006 8:29 pm    Post subject: Reply with quote

Tuohon varmaan riittää default gatewayn poisto:

Code:
route del default


Ja uuden gatewaynhän saa asetettua komennolla

Code:
route add default gw <gatewayn osoite>
Back to top
View user's profile Send private message
Obi-Lan
Apprentice
Apprentice


Joined: 21 Jan 2005
Posts: 230
Location: Riihimäki

PostPosted: Sat Nov 04, 2006 10:50 pm    Post subject: Reply with quote

Ee ainaki php liittymästä tulee vielä aliverkko routeihin messiin, ja tuntuu että koko kaupunki on samassa aliverkossa niin sekin pitäisi poistaa (tämä oikeesti haittaa). Tietty tiedän mikä se on ja voin tehdä spesifisen komennon sille, mutta kiinnostaisi tietää jos voin poistaa verkot määrittelemättä sen tarkemmin.
Back to top
View user's profile Send private message
jroo
n00b
n00b


Joined: 06 Mar 2005
Posts: 52
Location: Finland

PostPosted: Sun Nov 05, 2006 7:05 am    Post subject: Reply with quote

Eipä toiminutkaan tuo ehdotus...
Back to top
View user's profile Send private message
jroo
n00b
n00b


Joined: 06 Mar 2005
Posts: 52
Location: Finland

PostPosted: Sun Nov 05, 2006 7:55 am    Post subject: Reply with quote

Tuossa pitäisi olla toimiva python-skripti tuohon ongelmaan.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

from subprocess import Popen
from subprocess import PIPE

## \brief Returns route table as list of strings without the header row
def readRouteOutput():
  process = Popen( 'route -n', shell = True, stdout = PIPE )
  routeTable = process.stdout.readlines()
 
  return routeTable[ 2: ]


## \brief Transforms route table presented as string into tuple.
#
# Tuple contents:
# ( Type, IP, Netmask, Interface )
# Type is eithen 'host' or 'net'
# Interface is the name of the interface
def transformStringToRouteTuple( pRoute ):
  asList = pRoute.split()
 
  type = None
  if 'H' in asList[ 3 ]:
    type = 'host'
  else:
    type = 'net'
 
  ip = asList[ 0 ]
  netmask = asList[ 2 ]
  interface = asList[ 7 ]
 
  routeTuple = ( type, ip, netmask, interface )
 
  return routeTuple


def transformStringsToRouteTupleList( pRouteTable ):
  routeTupleList = []
  for route in pRouteTable:
    routeTupleList.append( transformStringToRouteTuple( route ) )
 
  return routeTupleList


def removeRoutesFromIf( pIfname, pRouteTable ):
  for route in pRouteTable:
    if route[ 3 ] == pIfname:
      command = 'route del' + \
                ' -' + route[ 0 ] + \
                ' ' + route[ 1 ]
     
      if route[ 0 ] == 'net':
        command += ' netmask ' + route[ 2 ]
     
      #print command
      os.system( command )



def main( pArgv ):
  if len( pArgv ) != 2:
    print "Give interface name."
  else:
    routesAsString = readRouteOutput()
    routeTable = transformStringsToRouteTupleList( routesAsString )
    removeRoutesFromIf( pArgv[ 1 ], routeTable )


if __name__ == '__main__':
  main(sys.argv)

Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Finnish All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum