visual-studio-2010ip-address

Finding hard-coded IP addresses using Visual Studio 2010 'Find in Files' utility (Ctrl+Shift+F)


I need to find all hard-coded IP addresses in some of our Visual Studio 2010 solutions.

How would I do this using the standard 'Find' utility (Ctrl+Shift+F) from Visual Studio 2010?


Solution

  • Unfortunately the regex search in Visual Studio 2010's "find in files" functionality is not Perl5-compatible. This regex pattern will match any numbers specified in a x.x.x.x style (ie. an IPv4-style address):

    [0-9]#\.[0-9]#\.[0-9]#\.[0-9]#
    

    According to the documentation, it doesn't look like there's a way to specify that a pattern must be repeated between 1 and 3 times which is what you really want for the IPv4-style octets, so the above pattern will also match version numbers like 2.0.20505.0.

    You can, however, limit the number of digits in the octets to 3 by specifying them explicitly as separate groups, although it gets very verbose:

    ([0-9]|([0-9][0-9])|([0-9][0-9][0-9]))\.([0-9]|([0-9][0-9])|([0-9][0-9][0-9]))\.([0-9]|([0-9][0-9])|([0-9][0-9][0-9]))\.([0-9]|([0-9][0-9])|([0-9][0-9][0-9]))
    

    This will still match version numbers with 3 or fewer digits per "section" of the version, like 4.0.0.0, but it will also match IPv4 addresses like 11.2.123.21.

    The format for writing IPv6 addresses is more flexible than for IPv4 and while it's probably possible to match them with a Visual Studio 2010 regex, it would be horribly complicated. :-)