-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadergetter.java
More file actions
65 lines (44 loc) · 1.39 KB
/
headergetter.java
File metadata and controls
65 lines (44 loc) · 1.39 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import java.util.Scanner;
public class headergetter{
public static void main(String[] args){
//String text = "<title>Jacks site</title>";
//System.out.println(titleExtr(text));
//System.out.println(text.charAt(bg));
//System.out.println(text.charAt(end+bg-1));
String title = "[!]No title found";
String site = args[0];
try{
URL url = new URL(site);
Scanner s2 = new Scanner(url.openStream());
//loop through each line and check if it contains the title tag and then if so extract the title from the line
while(s2.hasNext()){
String current = s2.nextLine();
if(current.contains("<title>")){
title = titleExtr(current);
System.out.println("[*]Title Found");
}
}
}
catch(MalformedURLException e){
System.out.println("[!]Error in url");
}
catch(IOException e){
System.out.println("[!]IO Exception occurred");
}
finally{
System.out.println("[+]"+title);
}
}
public static String titleExtr(String text){
//find begin index
int bg = text.indexOf("<title>") + 7;
//finds end index
int end = (text.substring(bg,text.length()).indexOf("</title>")) + (bg);
//a substring of the title
String title = text.substring(bg, end);
return title;
}
}