Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends...
I have a problem to find out IP Addresses from a given text file.
The Task is:
A file is given named conf.txt.
In conf.txt a lot of strings are present(like: ahcvyuADD����192.168.0.1��Z���q�%�Z��rt�������Z���q�%�Z��rt�5644585854554bvdfvvdtGHFJ GGHcbvvnnjkk122.16.8.90hh).

but we know there are three IP address also present in conf.txt file and ip addresses are not continue(some characters must present between two ip address).

Please suggest me which condition I should apply to find the ip address..

thanks.....
Posted
Comments
[no name] 27-Jul-13 5:41am    
Surely you can come up with an idea. There is however never going to be a 100% reliable method unless you can define clearer conditions.

1 solution

If you can, use a Regex:
(?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Fourth>2[0-4]\d|25[0-5]|[01]?\d\d?)


If you can't, then you will need to handle the file manually, and scan for a digit, look for up to two more, followed by a dot, then 1 to 3 digits, then a dot, etc. If you find fully valid info, it's probably an IP address! If you don't, keep looking... There is no "short cut" on that, I'm afraid.
 
Share this answer
 
Comments
[no name] 27-Jul-13 5:47am    
You can always ping a candidate as a test.
OriginalGriff 27-Jul-13 6:18am    
Yes - but you've still got to find them first! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900