CyberCodes
Java = Get public IP & Send report ot email Welcome

Reminders sa mga rehistradong myembro:

•ang lengwahe na gagamitin ay pawang english at tagalog lamang

•Bawal po dito ang pakikipag away

•Bawal ang mga shorcut na mga words
Example: txt, Pwd, at iba pa

•Bawal mababastos at masasakit na salita o anu mang makakasakit
ng damdamin ng isang myembro ng forum na ito

•use the "like" button if the post of the following user you think are usefull



Join the forum, it's quick and easy

CyberCodes
Java = Get public IP & Send report ot email Welcome

Reminders sa mga rehistradong myembro:

•ang lengwahe na gagamitin ay pawang english at tagalog lamang

•Bawal po dito ang pakikipag away

•Bawal ang mga shorcut na mga words
Example: txt, Pwd, at iba pa

•Bawal mababastos at masasakit na salita o anu mang makakasakit
ng damdamin ng isang myembro ng forum na ito

•use the "like" button if the post of the following user you think are usefull

CyberCodes
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Java = Get public IP & Send report ot email

Go down

Java = Get public IP & Send report ot email Empty Java = Get public IP & Send report ot email

Post by princeterror Sat Sep 22, 2012 4:49 am

mainclass
Code:
import java.io.ioexception;
import java.net.*;
import java.io.*;
 
public class dostuff {
public static void main(string args[]) throws ioexception {
  try {
  /* console output to file */
  printstream out = new printstream(new fileoutputstream("output.txt"));
  system.setout(out);
 
  /* get public ip address */
  java.net.url url = new java.net.url("http://www.whatismyip.org/"); //querry whatismyip.com
  java.net.httpurlconnection conn = (httpurlconnection)url.openconnection();
  java.io.inputstream instream = conn.getinputstream();
  java.io.inputstreamreader isr = new java.io.inputstreamreader(instream);
  java.io.bufferedreader br = new java.io.bufferedreader(isr);
  system.out.print("public ip address: " + br.readline());
 
  /* get private ip address */
  inetaddress priv = inetaddress.getlocalhost();
  system.out.println ("\nprivate ip address : " + priv );
 
  /* copy file contents */
  stringbuilder contents = new stringbuilder();
 
  try {
        bufferedreader input2 =  new bufferedreader(new filereader("output.txt"));
        try {
        string line = null;
       
        while (( line = input2.readline()) != null) {
          contents.append(line);
          contents.append(system.getproperty("line.separator"));
        }
        }
        finally {
        input2.close();
        }
  }
  catch (ioexception ex) {
        ex.printstacktrace();
  }
 
  /* convert stringbuilder to string */
  string str = contents.tostring();
 
  /* add email address to array and send report */
  postmailc x = new postmailc();
  string address [] = {"jsmith@mail.com"}; //enter your mail address here
  x.postmail(address, "ip report", str, "remote@mail.com");
  }
  catch (exception e) {
  e.printstacktrace();
  }
}
}

send mail class
Code:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
 
class postmailc {
public void postmail(string recipients[], string subject, string message , string from) throws messagingexception {
 
  boolean debug = false;
  /* configure smtp */
  properties props = new properties();
  props.put("mail.smtp.host", "smtp.yourisp.net"); //enter your isp's smtp server
 
  /* create properties and get the default session */
  session session = session.getdefaultinstance(props, null);
  session.setdebug(debug);
 
  /* create a message */
  message msg = new mimemessage(session);
 
  /* set the "from" and "to" address */
  internetaddress addressfrom = new internetaddress(from);
  msg.setfrom(addressfrom);
  internetaddress[] addressto = new internetaddress[recipients.length];
 
  for (int i = 0; i < recipients.length; i++) {
  addressto[i] = new internetaddress(recipients[i]);
  }
 
  msg.setrecipients(message.recipienttype.to, addressto);
 
  /* set subject and content type */
  msg.setsubject(subject);
        msg.setcontent(message, "text/plain");
        transport.send(msg);
}
}
princeterror
princeterror
Universal Moderator
Universal Moderator

Posts : 272
Credits : 11465
Fame : 81
Join date : 2012-06-07
Age : 32

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum