Created
September 11, 2023 17:38
-
-
Save borymskyi/a3f32e2b45e0af5299005901d49180e4 to your computer and use it in GitHub Desktop.
awd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
String[] ipAddresses = { | |
"192.168.1.1", | |
"10.0.0.1", | |
"172.16.0.1", | |
"255.255.255.0", | |
"192.168.256.1", | |
"192.168.1.2", | |
"10.0.0.2", | |
"172.16.0.2", | |
"192.168.1.3" | |
}; | |
// Регулярное выражение для проверки IP-адресов | |
Pattern pattern = Pattern.compile("^(?:\\d{1,3}\\.){3}\\d{1,3}$"); | |
// Массив строк с IP-адресами в черном списке | |
String[] ipBlackList = { | |
}; | |
// Проверка каждого IP-адреса | |
for (int i = 0; i < ipAddresses.length; i++) { | |
// Проверка на соответствие регулярному выражению | |
if (!pattern.matcher(ipAddresses[i]).matches()) { | |
throw new IllegalArgumentException("Некорректный IP-адрес: " + ipAddresses[i]); | |
} | |
// Проверка на принадлежность к черному списку | |
for (int j = 0; j < ipBlackList.length; j++) { | |
if (ipAddresses[i].equals(ipBlackList[j])) { | |
throw new IllegalArgumentException("IP-адрес в черном списке: " + ipAddresses[i]); | |
} | |
} | |
} | |
System.out.println("Все IP-адреса прошли проверку."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment