Logger
This commit is contained in:
+20
-22
@@ -1,23 +1,21 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>WebCallerID</groupId>
|
||||
<artifactId>WebCallerID</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ant</groupId>
|
||||
<artifactId>ant-apache-log4j</artifactId>
|
||||
<version>1.6.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>WebCallerID</groupId>
|
||||
<artifactId>WebCallerID</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -9,36 +9,23 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.client.DefaultRedirectStrategy;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
|
||||
public class CallerIdClient {
|
||||
|
||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||
|
||||
private final static Logger log = Logger.getLogger(CallerIdClient.class);
|
||||
|
||||
String password = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode("53795306".getBytes());
|
||||
String cookie;
|
||||
|
||||
public CallerIdClient() {
|
||||
|
||||
// com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(null);
|
||||
|
||||
// plain Java
|
||||
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
|
||||
|
||||
try {
|
||||
login();
|
||||
getList();
|
||||
@@ -46,20 +33,12 @@ public class CallerIdClient {
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
// Apache http client
|
||||
// try {
|
||||
// apacheLogin();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void login() throws Exception {
|
||||
System.out.println("--- login() --------------------------------------");
|
||||
log.info("login()");
|
||||
String body = "Username=" + URLEncoder.encode("admin", "UTF-8") + "&" + "Password=" + password;
|
||||
System.out.println(body);
|
||||
log.info(body);
|
||||
|
||||
URL url2 = new URL("https://speedport.ip/index/login.cgi");
|
||||
HttpURLConnection connection = (HttpURLConnection) url2.openConnection();
|
||||
@@ -92,9 +71,7 @@ public class CallerIdClient {
|
||||
}
|
||||
|
||||
private void getList() throws Exception {
|
||||
System.out.println("--- getList() --------------------------------------");
|
||||
//https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3,xctyNRvrwuh
|
||||
|
||||
log.info("getList()");
|
||||
URL u = new URL("https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
||||
URLConnection urlConn = u.openConnection();
|
||||
String cookieString = "SessionID_R3=" + cookie;
|
||||
@@ -106,104 +83,27 @@ public class CallerIdClient {
|
||||
}
|
||||
|
||||
private void logout() throws Exception {
|
||||
System.out.println("--- logout() --------------------------------------");
|
||||
URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
|
||||
URLConnection urlConn = myUrl.openConnection();
|
||||
log.info("logout()");
|
||||
// URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
|
||||
URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?cookie=SessionID_R3," + cookie);
|
||||
String cookieString = "SessionID_R3=" + cookie;
|
||||
URLConnection urlConn = myUrl.openConnection();
|
||||
urlConn.setRequestProperty("Cookie", cookieString);
|
||||
urlConn.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
||||
urlConn.connect();
|
||||
|
||||
// URL u = new URL("https://speedport.ip/pub/top_beenden.php");
|
||||
// // https://speedport.ip/logout.cgi?RequestFile=/pub/top_beenden.php
|
||||
// String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
|
||||
// System.out.println("Logout:");
|
||||
// System.out.println(r);
|
||||
showStatus(urlConn);
|
||||
|
||||
myUrl = new URL("https://speedport.ip/");
|
||||
urlConn = myUrl.openConnection();
|
||||
urlConn.setRequestProperty("Cookie", cookieString);
|
||||
urlConn.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
||||
urlConn.connect();
|
||||
showStatus(urlConn);
|
||||
}
|
||||
|
||||
private void plainJava() throws Exception {
|
||||
|
||||
URL url = new URL("https://speedport.ip/");
|
||||
URLConnection conn = url.openConnection();
|
||||
|
||||
for (int i = 0;; i++) {
|
||||
String name = conn.getHeaderFieldKey(i);
|
||||
String value = conn.getHeaderField(i);
|
||||
if (name == null && value == null) {
|
||||
break;
|
||||
}
|
||||
if (name == null) {
|
||||
System.out.println("Server HTTP version, Response code:");
|
||||
System.out.println(value);
|
||||
System.out.print("\n");
|
||||
} else {
|
||||
System.out.println(name + "=" + value);
|
||||
}
|
||||
}
|
||||
|
||||
// Startseite
|
||||
URL u = new URL("https://speedport.ip/");
|
||||
String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
|
||||
System.out.println(r);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void apacheLogin() throws Exception {
|
||||
httpclient.setRedirectStrategy(new DefaultRedirectStrategy() {
|
||||
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) {
|
||||
boolean isRedirect = false;
|
||||
try {
|
||||
isRedirect = super.isRedirected(request, response, context);
|
||||
} catch (ProtocolException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!isRedirect) {
|
||||
int responseCode = response.getStatusLine().getStatusCode();
|
||||
if (responseCode == 301 || responseCode == 302) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return isRedirect;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* // Apache 1 HttpPost httpPost = new
|
||||
* HttpPost("https://speedport.ip/index/login.cgi"); List<NameValuePair>
|
||||
* nvps = new ArrayList<NameValuePair>(); nvps.add(new
|
||||
* BasicNameValuePair("Username", "admin")); nvps.add(new
|
||||
* BasicNameValuePair("Password", password)); httpPost.setEntity(new
|
||||
* UrlEncodedFormEntity(nvps)); HttpResponse response2 =
|
||||
* httpclient.execute(httpPost);
|
||||
*
|
||||
* try { System.out.println(response2.getStatusLine()); HttpEntity
|
||||
* entity2 = response2.getEntity(); // do something useful with the
|
||||
* response body // and ensure it is fully consumed
|
||||
* EntityUtils.consume(entity2); } finally {
|
||||
* httpPost.releaseConnection(); }
|
||||
*/
|
||||
|
||||
/*
|
||||
* // Apache 2 PostMethod post = new
|
||||
* PostMethod("https://speedport.ip/index/login.cgi"); NameValuePair[]
|
||||
* data = { new NameValuePair("Username", "admin"), new
|
||||
* NameValuePair("Password", password) }; post.setRequestBody(data);
|
||||
*
|
||||
* // post.setParameter("Cookie", "SessionID_R3=Rian5OU7Cuj");
|
||||
* post.addRequestHeader("Referer", "https://speedport.ip/");
|
||||
* post.addRequestHeader("Cookie", "SessionID_R3=Rian5OU7Cuj");
|
||||
*
|
||||
* try { int resp = client.executeMethod(post);
|
||||
* System.out.println("Response Code: " + resp); } catch (HttpException
|
||||
* e1) { e1.printStackTrace(); } catch (IOException e1) {
|
||||
* e1.printStackTrace(); }
|
||||
*
|
||||
* // execute method and handle any error responses. try { InputStream
|
||||
* in = post.getResponseBodyAsStream(); System.out.println("response: "
|
||||
* + in); } catch (IOException e) { e.printStackTrace(); }
|
||||
*/
|
||||
|
||||
httpclient.getConnectionManager().shutdown();
|
||||
|
||||
private void showStatus(URLConnection connection) throws IOException {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
log.info("HTTP Status " + httpConnection.getResponseCode() + " - " + httpConnection.getURL());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user