• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

How do i generate Ip addresses from Regular Expression

I am getting Regular Expression as an input for IP Address. ex. 192.168.(2[0-4]\d|25[0-5]|[01]?\d\d?).\.(2[0-4]\d|25[0-5]|[01]?\d\d?). Having this, i need to generate list of IP Addresses starting from 192.168.1.1 to 192.168.254.254. How could i achieve this in C#.NET.

Could anybody help?

Thanks in advance..
0
Loganathan Natarajan
Asked:
Loganathan Natarajan
  • 3
1 Solution
 
ddrudikCommented:
You would need to loop through the target addresses to test each one against your pattern to determine a match.  Another option would be to have all IP addresses in a text file in which you match each line against the pattern.  There really isn't a simple function to do this well that I am aware of, what is the goal?

Note that . chars need to be escaped in regex patterns, as you did in one place but not the others, also in the one place where you did escape the . you seem to have an extra unescaped . before it.
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
I am doing a program that will fetch the name of the computers available over a network. In order to get the computer name i need to provide the Ip address. There are many subnets available over the network. It is very difficult to enter all the IP addresses.
So, i thought i could use Regular Expression to avoid this difficulty.
I thought this could be generalized and used for any network.
0
 
ddrudikCommented:
I would recommend you consider a pre-made module for this, if you can intergrate Perl in your solution there are subnet and IP matching modules available:
http://search.cpan.org/
0
 
ddrudikCommented:
Thanks for the question and the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now