Problem with wildcards with route delete

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jharris
Posts: 4
Joined: 18 May 2010 00:55

Problem with wildcards with route delete

#1 Post by jharris » 26 Apr 2013 18:02

I am trying to delete a route using route.exe under Windows XP. I need to use a wildcard for the gateway because the exact IP address varies. Here is the excerpt from the routing table showing the line I am trying to delete:

Code: Select all

Network Destination        Netmask          Gateway     Interface    Metric
      192.168.1.0    255.255.255.0   192.168.200.28  192.168.200.28       1
I am trying to use this command:
route delete 192.168.1.0 192.168.200.*
It pauses for a few seconds and gives me "route: bad gateway address 192.168.200.*"

According to the documentation from route /?, this should work:

If the command is print or delete, the Gateway parameter can be omitted and wildcards can be used for the destination and gateway. The Destination value can be a wildcard value specified by an asterisk (*). If the destination specified contains an asterisk (*) or a question mark (?), it is treated as a wildcard and only matching destination routes are printed or deleted. The asterisk matches any string, and the question mark matches any single character. For example, 10.*.1, 192.168.*, 127.*, and *224* are all valid uses of the asterisk wildcard.
I have tried many variations of where to put the *, using ? instead, etc. but I always get the same error. What am I doing wrong? Any ideas?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Problem with wildcards with route delete

#2 Post by Endoro » 26 Apr 2013 20:45

"192.168.200.*" is not a valid IP adress. Don't use wildcards here.

jharris
Posts: 4
Joined: 18 May 2010 00:55

Re: Problem with wildcards with route delete

#3 Post by jharris » 26 Apr 2013 21:17

Endoro wrote:"192.168.200.*" is not a valid IP adress. Don't use wildcards here.
Endoro, I'm confused. In the documentation I sited, it lists several examples of valid IP addresses using wild cards including 192.168.*, pretty much what I am trying to do.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem with wildcards with route delete

#4 Post by foxidrive » 26 Apr 2013 22:11

The help in Win 8 might be better. Try using * as the gateway or leave it out.

It says that pattern matching is only available in the PRINT command.

Of course Win 8 route.exe could have been enhanced in ways.


Code: Select all

c:\>route

Manipulates network routing tables.

ROUTE [-f] [-p] [-4|-6] command [destination]
                  [MASK netmask]  [gateway] [METRIC metric]  [IF interface]

  -f           Clears the routing tables of all gateway entries.  If this is
               used in conjunction with one of the commands, the tables are
               cleared prior to running the command.

  -p           When used with the ADD command, makes a route persistent across
               boots of the system. By default, routes are not preserved
               when the system is restarted. Ignored for all other commands,
               which always affect the appropriate persistent routes.

  -4           Force using IPv4.

  -6           Force using IPv6.

  command      One of these:
                 PRINT     Prints  a route
                 ADD       Adds    a route
                 DELETE    Deletes a route
                 CHANGE    Modifies an existing route
  destination  Specifies the host.
  MASK         Specifies that the next parameter is the 'netmask' value.
  netmask      Specifies a subnet mask value for this route entry.
               If not specified, it defaults to 255.255.255.255.
  gateway      Specifies gateway.
  interface    the interface number for the specified route.
  METRIC       specifies the metric, ie. cost for the destination.

All symbolic names used for destination are looked up in the network database
file NETWORKS. The symbolic names for gateway are looked up in the host name
database file HOSTS.

If the command is PRINT or DELETE. Destination or gateway can be a wildcard,
(wildcard is specified as a star '*'), or the gateway argument may be omitted.

If Dest contains a * or ?, it is treated as a shell pattern, and only
matching destination routes are printed. The '*' matches any string,
and '?' matches any one char. Examples: 157.*.1, 157.*, 127.*, *224*.

Pattern match is only allowed in PRINT command.
Diagnostic Notes:
    Invalid MASK generates an error, that is when (DEST & MASK) != DEST.
    Example> route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1 IF 1
             The route addition failed: The specified mask parameter is invalid.
 (Destination & Mask) != Destination.

Examples:

    > route PRINT
    > route PRINT -4
    > route PRINT -6
    > route PRINT 157*          .... Only prints those matching 157*

    > route ADD 157.0.0.0 MASK 255.0.0.0  157.55.80.1 METRIC 3 IF 2
             destination^      ^mask      ^gateway     metric^    ^
                                                         Interface^
      If IF is not given, it tries to find the best interface for a given
      gateway.
    > route ADD 3ffe::/32 3ffe::1

    > route CHANGE 157.0.0.0 MASK 255.0.0.0 157.55.80.5 METRIC 2 IF 2

      CHANGE is used to modify gateway and/or metric only.

    > route DELETE 157.0.0.0
    > route DELETE 3ffe::/32

jharris
Posts: 4
Joined: 18 May 2010 00:55

Re: Problem with wildcards with route delete

#5 Post by jharris » 27 Apr 2013 00:34

Looks like they updated the documentation for Windows 8. Kind of. It is still misleading:

Code: Select all

If the command is PRINT or DELETE. Destination or gateway can be a wildcard,
(wildcard is specified as a star '*'), or the gateway argument may be omitted.

If Dest contains a * or ?, it is treated as a shell pattern, and only
matching destination routes are printed. The '*' matches any string,
and '?' matches any one char. Examples: 157.*.1, 157.*, 127.*, *224*.

Pattern match is only allowed in PRINT command.

First it says you can use wildcard in PRINT or DELETE, but later than pattern matching is only allowed in PRINT. BTW, that last line above is missing from the XP route help. Apparently, MS noticed the problem and tried to address it in the documentation, but didn't quite get it all!

I did find that it works without specifying the gateway at all. The problem I was having was that I had 2 routes to the same destination through different gateways, one that I wanted and one set up by my company VPN. I wanted to specify the VPN to delete, but it appears that if I just leave out the gateway, the VPN gets deleted but the one I want to keep stays around. Not sure why, but it works!

Post Reply