Tag: java

Java

Search Google Programmatically with Java

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL;   public class Google_Search { private final String _url; private URL _url_obj; private HttpURLConnection _connection; private final String _userAgent; private int _responseCode; private StringBuffer _totalResults; private final int _quantity; private final int _start; private final String _searchTerm;   public Google_Search(String SearchTerm){ _url = "http://www.google.com"; _userAgent …

Java

List all running processes in Java

Tasklist displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer. void ListAllProcesses() { try { Process p = Runtime.getRuntime().exec("tasklist"); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (Exception …

Java

Open source java library for libpcap and winpcap

jNetPcap is an open-source java library. It contains: A Java wrapper for nearly all libpcap library native calls Decodes captured packets in real-time Provides a large library of network protocols (core protocols) Users can easily add their own protocol definitions using java SDK jNetPcap uses a mixture of native and java implementation for optimum packet …

Java

Save user settings in Java application

Class: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties;     public class configManager { private Properties _properties; private final String _filename = "my.properties";   public configManager(){ this._properties = new Properties(); File file=new File(this._filename);   if (!file.exists()) { try { file.createNewFile(); } catch (IOException ex) { System.err.println(ex.toString()); } }   try { this._properties.load(new …

Java

Check if file or directory exists in Java

Check if file exists: File f = new File("/path/to/filename"); if(f.exists()){ .. }File f = new File("/path/to/filename"); if(f.exists()){ .. } Check if directory exists: File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }

Java

Encrypt string using AES 128 – Java

You need Apache Commons Codec. package encryption.aes;   import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64;   public class aes128 {   public static void main(String args[]) { String plain = "testtesttesttesttesttesttesttest"; String ivkey = "abcdefgh12345678";   byte[] ivraw = ivkey.getBytes(); SecretKeySpec skeySpec = new SecretKeySpec(ivraw, "AES"); …

Cross-Platform, Java

Capture screen shot in Java

It’s really easy to capture screen shots using java code. Let’s see how: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 package screenshot;   import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO;   public class Screenshot { public static void main(String[] args) …