// Author: Manish Raj
// Homepage: http://www.technoslab.in
// Contact: technoslab[@gmail.com]
public class application extends javax.swing.JFrame {
public application() {
initComponents();
}
public boolean send(String username, String password, String number, String message) {
statusField.setText("Status: Attempting login...");
String loginResult = sendPost("http://site1.way2sms.com/Login1.action", "http://site1.way2sms.com/content/index.html", "username=" + username + "&password=" + password, "");
if (loginResult.indexOf("Main.action") > 0) {
statusField.setText("Status: Logged in");
String url = inbetween(loginResult, "Location: ", "\r\n");
String cookie = inbetween(loginResult, "Set-Cookie: ", "\r\n");
String instantResult = sendPost("http://site1.way2sms.com/jsp/InstantSMS.jsp", "", "", cookie);
statusField.setText("Status: Retrieving instantSMS form...");
String action = inbetween(instantResult, " 0) {
statusField.setText("Status: Sending message...");
return true;
} else {
return false;
}
}
} else {
return false;
}
}
public String inbetween(String str, String start, String end) {
String ret = "";
try {
ret = str.substring(str.indexOf(start) + start.length(),
str.indexOf(end, str.indexOf(start) + start.length()));
} catch (Exception e) {
}
return ret;
}
public String sendPost(String link, String ref, String post, String cookie) {
StringBuilder sb = new StringBuilder("");
try {
java.net.URL url = new java.net.URL(link);
String nl = "\r\n";
String request = ""
+ "POST " + url.getPath() + " HTTP/1.1" + nl
+ "Host: " + url.getHost() + nl
+ "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + nl
+ "Cache-Control: max-age=0" + nl
+ "Connection: Close" + nl
+ "Keep-Alive: 300" + nl
+ "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + nl
+ "Accept-Language: en-us,en;q=0.5" + nl
+ "Referer: " + ref + nl
+ "Content-Type: application/x-www-form-urlencoded" + nl
+ "Content-Length: " + post.length() + nl
+ "Cookie: " + cookie + nl
+ "User-Agent: Mozilla/5.0 (Windows;U;Windows NT 5.0;en-US;rv:1.4) Gecko/20030624 Netscape/7.1 (ax)" + nl + nl
+ post;
//System.out.println(request);
java.net.Socket remoteConnection = new java.net.Socket(url.getHost(), 80);
java.io.OutputStream remoteOutputStream = remoteConnection.getOutputStream();
java.io.InputStream remoteInputStream = remoteConnection.getInputStream();
remoteOutputStream.write(request.getBytes());
remoteOutputStream.flush();
int inputChar = -1;
while ((inputChar = remoteInputStream.read()) != -1) {
sb.append((char) inputChar);
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
@SuppressWarnings("unchecked")
private void initComponents() {
usernameField = new javax.swing.JTextField();
numberField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
messageBox = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
sendButton = new javax.swing.JButton();
lengthField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
registerLink = new javax.swing.JLabel();
passwordField = new javax.swing.JPasswordField();
statusField = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Way2SMS desktop App by www.technoslab.in");
setResizable(false);
messageBox.setColumns(20);
messageBox.setLineWrap(true);
messageBox.setRows(5);
messageBox.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
messageBoxKeyTyped(evt);
}
});
jScrollPane1.setViewportView(messageBox);
jLabel1.setText("Username / Mobile number");
jLabel2.setText("Password");
sendButton.setText("Send");
sendButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendButtonActionPerformed(evt);
}
});
lengthField.setText(" 0");
jLabel3.setText("+91");
registerLink.setText("Don't have an account yet?");
registerLink.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
registerLink.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
registerLinkMouseClicked(evt);
}
});
statusField.setText("Status: IDLE...");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(numberField, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
.addGap(147, 147, 147)
.addComponent(lengthField, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(77, 77, 77)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(usernameField, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
.addComponent(passwordField, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addComponent(statusField, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sendButton))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(registerLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(numberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(lengthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sendButton)
.addComponent(statusField))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(registerLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private void registerLinkMouseClicked(java.awt.event.MouseEvent evt) {
try {
java.awt.Desktop.getDesktop().browse(new java.net.URI("http://way2sms.com/"));
} catch (Exception e) {
}
}
private void messageBoxKeyTyped(java.awt.event.KeyEvent evt) {
if (messageBox.getText().length() > 160) {
messageBox.setText(messageBox.getText().substring(0, 160));
}
lengthField.setText(" " + messageBox.getText().length());
}
private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {
char[] p = passwordField.getPassword();
StringBuilder pw = new StringBuilder();
for (int i = 0; i < p.length; i++) {
pw.append(p[i]);
}
boolean result = send(usernameField.getText(), pw.toString(), numberField.getText(), messageBox.getText());
if (result) {
statusField.setText("Status: Message sent successfully...");
} else {
statusField.setText("Status: Sending failed...");
}
}
public static void main(String args[]) {
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new application().setVisible(true);
}
});
}
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField lengthField;
private javax.swing.JTextArea messageBox;
private javax.swing.JTextField numberField;
private javax.swing.JPasswordField passwordField;
private javax.swing.JLabel registerLink;
private javax.swing.JButton sendButton;
private javax.swing.JLabel statusField;
private javax.swing.JTextField usernameField;
}