diff --git a/src/tracker/Tracker.java b/src/tracker/Tracker.java index 364ab73..7923024 100644 --- a/src/tracker/Tracker.java +++ b/src/tracker/Tracker.java @@ -7,6 +7,7 @@ import tools.Directories; import tools.Logger; import tools.LogLevel; import tools.TestPort; +import tools.TestLegitIP; /** Tracker implementation * First argument of main method is port listened by the tracker, and is mandatory. @@ -42,16 +43,20 @@ public class Tracker { final String defaultPort = "6969"; final String defaultHostname = "localhost"; Scanner scanner = new Scanner(System.in); + TestLegitIP testLegitIP = new TestLegitIP(); + TestPort testPortTracker = new TestPort(); Tracker t; - System.out.println("Tracker Server, enter hostname to bind (default = localhost): "); - String hostname = scanner.nextLine(); - if(hostname.equals("")){ - hostname = defaultHostname; - System.out.println("using default hostname : " + hostname); - } else{ - System.out.println("using hostname : " + hostname); - } + do{ + System.out.println("Tracker Server, enter hostname to bind (default = localhost): "); + String hostname = scanner.nextLine(); + if(hostname.equals("")){ + hostname = defaultHostname; + System.out.println("using default hostname : " + hostname); + } + } while (!testLegitIP.TestIP(hostname)) + System.out.println("using hostname : " + hostname); + System.out.println("enter port (default = 6969): "); String port = scanner.nextLine(); if(port.equals("")){ @@ -60,7 +65,6 @@ public class Tracker { } else { System.out.println("using port : " + port); } - TestPort testPortTracker = new TestPort(); if(testPortTracker.testPortTracker(Integer.parseInt(port))){ t = new Tracker(port); }