-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOtherTopLevelDomains.java
More file actions
35 lines (28 loc) · 1.1 KB
/
OtherTopLevelDomains.java
File metadata and controls
35 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
public class OtherTopLevelDomains {
public ArrayList<String> findOtherDomains(String url, String domains) throws MalformedURLException {
String[] domain = domains.split(" ");
URL urlToCheck = new URL(url);
CheckHttpStatus checkHttpStatus = new CheckHttpStatus();
ArrayList<String> otherTLDs = new ArrayList<>();
for(int i=0; i<domain.length;i++ )
{
String[] domainNameParts = urlToCheck.getHost().split("\\.");
if (!domainNameParts[domainNameParts.length - 1].equals(domain[i]))
{
String newUrl = urlToCheck.toString().replace(domainNameParts[domainNameParts.length - 1], domain[i]);
if (checkHttpStatus.getHTTPStatus(newUrl) >= 200 && checkHttpStatus.getHTTPStatus(newUrl) <= 399)
{
otherTLDs.add(domain[i]);
}
else
continue;
}
else
continue;
}
return otherTLDs;
}
}