You are given an absolute or relative path to a directory on the local file system.
Write a program that recursively traverses every subdirectory under that root directory, reads every regular file, finds all valid IPv4 addresses contained in those files, and prints the addresses in lexicographic order.
A valid IPv4 address has exactly four decimal octets separated by dots. Each octet must be an integer from 0 to 255. Leading zeros are not allowed unless the octet is exactly 0. For example, 192.168.0.1 and 0.0.0.0 are valid, while 256.1.1.1, 01.2.3.4, 1.2.3, and 1.2.3.4.5 are invalid.
Clarifications:
-
Recursively visit all nested folders under the input path.
-
Only scan regular files.
-
Treat file contents as text; if a file cannot be decoded or read, handle it gracefully according to your language's best practices.
-
If the same valid IP address appears multiple times, print it only once.
-
The final output should contain one IP address per line, sorted lexicographically as strings.