From 9c5bfc5430ac353fe5d4be620f73ea6de24f7110 Mon Sep 17 00:00:00 2001 From: flavien Date: Mon, 23 Mar 2020 18:07:26 +0100 Subject: [PATCH] added a method to test if hostnames are legitimate --- src/tools/TestLegitIP.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/tools/TestLegitIP.java diff --git a/src/tools/TestLegitIP.java b/src/tools/TestLegitIP.java new file mode 100644 index 0000000..aa271f3 --- /dev/null +++ b/src/tools/TestLegitIP.java @@ -0,0 +1,28 @@ +package tools; + +/** Test if IP are legitimate. + * @author Louis Royer + * @author Flavien Haas + * @author JS Auge + * @version 1.0 + */ +public class TestLegitIP { + + public boolean TestIP(String hostname) { + if(hostname.equals("localhost")){ + return true; + } + else{ + String[] ipArray = hostname.split("\\."); + if(ipArray.length != 4){ + return false; + } + for(int i= 0; i < ipArray.length; i++){ + if((Integer.parseInt(ipArray[i]) > 255) || (Integer.parseInt(ipArray[i]) < 0)){ + return false; + } + } + } + return true; + } +}