Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Console + ConsoleExample Changes #18

Merged
merged 1 commit into from Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# vHackAPI-Java
[![Discord](https://img.shields.io/badge/Chat-%20on%20Discord-738bd7.svg)](https://discord.gg/PHgESQn) [![Build Status](https://travis-ci.org/vHack-API/vHackAPI-Java.svg?branch=master)](https://travis-ci.org/vHack-API/vHackAPI-Java) [![Downloads](https://img.shields.io/github/downloads/vHack-API/vHackAPI-Java/total.svg)]() [![GitHub release](https://img.shields.io/github/release/vHackAPI/vHackAPI-Java.svg)]()

### Contributors: [@Checkium](https://github.com/checkium), [@dude24760](https://github.com/dude24760), [@angelbirth](https://github.com/angelbirth), [@Qup42](https://github.com/Qup42)
### Contributors: [@Checkium](https://github.com/checkium), [@dude24760](https://github.com/dude24760), [@angelbirth](https://github.com/angelbirth), [@Qup42](https://github.com/Qup42), [@tr0teK](https://github.com/tr0teK)
###### Don't forget to add your name here when you pull request.
Current feature list:
- Ability to scan the network for IP addresses.
Expand Down
23 changes: 11 additions & 12 deletions src/examples/ConsoleExample.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package examples;

import java.util.ArrayList;
import java.util.List;
//import java.util.ArrayList;
//import java.util.List;

import me.checkium.vhackapi.vHackAPI;
import me.checkium.vhackapi.vHackAPIBuilder;
Expand All @@ -11,16 +11,15 @@
public class ConsoleExample {
public static void main(String[] args) {
vHackAPI api = new vHackAPIBuilder().password("pass").username("user").getAPI();
List<String> ip = api.getConsole().getIPs(1, false, false);
List<ScannedNode> scanned = api.getConsole().scanIPs(ip);
String ip = api.getConsole().getIP(false, false);
ScannedNode scanned = api.getConsole().scanIP(ip);

if(scanned.get(0).getSuccessRate() <= 90 && scanned.get(0).isAnonymous()) {
ArrayList<TransferResult> transfer = api.getConsole().trTransferIPs((ArrayList<String>) ip);
if(transfer.get(0).getSuccess()){
System.out.println("Got $" + transfer.get(0).getMoneyAmount());
System.out.println("Gained " + transfer.get(0).getRepGained() + " rep.");
}
}

if(scanned.getSuccessRate() >= 70) {
TransferResult transfer = api.getConsole().transferTrojanTo(scanned);
if(transfer.getSuccess()){
System.out.println("Got $" + transfer.getMoneyAmount());
System.out.println("Gained " + transfer.getRepGained() + " rep.");
}
}
}
}
55 changes: 40 additions & 15 deletions src/me/checkium/vhackapi/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public Console(String user, String pass, String uHash) {
//return this;
}

/**
*
* Get IP from console
*
* @param global Use global?
* @param attacked Get already attacked IPs?
*/
public String getIP(boolean attacked, boolean global) throws JSONException {
String result = null;
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::global", username + "::::" + password + "::::" + userHash + "::::" + (global?"1":"0"), "vh_network.php");
JSONArray jSONArray = json.getJSONArray("data");
result = jSONArray.getJSONObject(0).getString("ip");
return result;
}

/**
*
* Get IPs from console
Expand All @@ -37,16 +52,12 @@ public Console(String user, String pass, String uHash) {
* @param global Use global?
* @param attacked Get already attacked IPs?
*/
public ArrayList<String> getIPs(int number, boolean attacked, boolean global){
public ArrayList<String> getIPs(int number, boolean attacked, boolean global) throws JSONException {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> temporary = new ArrayList<String>();
int globali = 0;
if (global) {
globali = 1;
}
if (number > 10) {
for (int i = 10; i <= number + 9; i = i + 10) {
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::global", username + "::::" + password + "::::" + userHash + "::::" + Integer.toString(globali), "vh_network.php");
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::global", username + "::::" + password + "::::" + userHash + "::::" + (global?"1":"0"), "vh_network.php");
JSONArray jSONArray = json.getJSONArray("data");
for (int j = 0; j <= jSONArray.length() - 1; j++) {
JSONObject ip = jSONArray.getJSONObject(j);
Expand All @@ -58,7 +69,7 @@ public ArrayList<String> getIPs(int number, boolean attacked, boolean global){
result.add(temporary.get(k));
}
} else {
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::global", username + "::::" + password + "::::" + userHash + "::::" + Integer.toString(globali), "vh_network.php");
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::global", username + "::::" + password + "::::" + userHash + "::::" + (global?"1":"0"), "vh_network.php");
JSONArray jSONArray = json.getJSONArray("data");
for (int k = 0; k < number; k++) {
result.add(jSONArray.getJSONObject(k).getString("ip"));
Expand All @@ -67,14 +78,31 @@ public ArrayList<String> getIPs(int number, boolean attacked, boolean global){
return result;
}

public ScannedNode scanIP(String ip) {
InputStream is;
BufferedReader rd;
ScannedNode result = null;
try {
is = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + ip, "vh_scan.php")).openStream();
rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String[] temp = ReadBigStringIn(rd);
result = new ScannedNode(temp);
result.setIP(ip);
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException|IOException e) {
e.printStackTrace();
}
return result;
}

public List<ScannedNode> scanIPs(List<String> ips) {
InputStream is;
BufferedReader rd;
List<ScannedNode> array = new ArrayList<>();
ScannedNode result;

for (String ip : ips) {
try{
try {
is = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + ip, "vh_scan.php")).openStream();
rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String[] temp = ReadBigStringIn(rd);
Expand All @@ -83,7 +111,6 @@ public List<ScannedNode> scanIPs(List<String> ips) {
array.add(result);
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException|IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Expand All @@ -94,15 +121,13 @@ public TransferResult transferTrojanTo(ScannedNode node) throws JSONException {
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::target", username + "::::" + password + "::::" + userHash + "::::" + node.getIP(), "vh_trTransfer.php");
return new TransferResult(json, node.getIP());
}


public ArrayList<TransferResult> trTransferIPs(ArrayList<String> ips) {
public ArrayList<TransferResult> transferTrojansTo(ArrayList<ScannedNode> nodes) throws JSONException {
ArrayList<TransferResult> array = new ArrayList<TransferResult>();
TransferResult result;
for (int j = 0; j < ips.size(); j++) {

JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::target", username + "::::" + password + "::::" + userHash + "::::" + ips.get(j), "vh_trTransfer.php");
result = new TransferResult(json, ips.get(j));
for (int j = 0; j < nodes.size(); j++) {
JSONObject json = Utils.JSONRequest("user::::pass::::uhash::::target", username + "::::" + password + "::::" + userHash + "::::" + nodes.get(j).getIP(), "vh_trTransfer.php");
result = new TransferResult(json, nodes.get(j).getIP());
array.add(result);
}
return array;
Expand Down