nome para ip & ip para nome com ping
Publicado por Abraao dos Santos Carvalho 03/10/2007
[ Hits: 7.396 ]
Esse script foi feito no netbeans, ele traduz ip para nome, nome para ip, e faz um ping.
Obs: para o ping, você deve entrar com o nome do site. Também funciona em rede local. Se alguém melhorar esse script, por favor mande para mim, pois estou aprendendo ainda... peujrcarvalho@hotmail.com
/*
* Apresentação.java
*
* Created on 22 de Setembro de 2007, 01:20
*/
package Apresentação;
import java.net.*;
import java.io.*;
import java.util.*;
/**
*
* @author Abraão
*/
public class Apresentação extends javax.swing.JFrame {
/** Creates new form Apresentação */
public Apresentação() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
janela1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
janela2 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Informe o site ou o IP");
jButton1.setText("Enter");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel2.setText("IP para nome");
jButton2.setText("Enter");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel3.setText("Nome para IP");
jButton3.setText("Enter");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel4.setText("Ping");
jLabel5.setText("Resposta");
jButton4.setText("Sair");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("Limpar");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton1)
.add(jLabel2))
.add(78, 78, 78)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel5)
.add(jButton2))))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(141, 141, 141)
.add(jLabel1))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(118, 118, 118)
.add(janela1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 137, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 53, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jLabel4)
.add(63, 63, 63))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButton5)
.add(jButton3))
.add(39, 39, 39))))
.add(layout.createSequentialGroup()
.add(79, 79, 79)
.add(janela2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
.add(86, 86, 86))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jButton4)
.addContainerGap(349, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(janela1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(16, 16, 16)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jLabel4)
.add(jLabel3))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton3)
.add(jButton2))
.add(30, 30, 30)
.add(jLabel5)
.add(20, 20, 20)
.add(janela2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 44, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 49, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton4)
.add(jButton5))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
String endereco;
endereco = (janela1.getText());
try {
if (InetAddress.getByName(endereco).isReachable(50000))
janela2.setText(" Ping OK ");
else
janela2.setText(" Ping falhou ");
}
catch (Exception e) {
janela2.setText("Ping falhou");
}
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
String IP=(janela1.getText());
try{
String serv = InetAddress.getByName(IP).getHostName();
janela2.setText(serv);
}
catch (UnknownHostException serv){
janela2.setText("Não foi possivel resolver do servidor");
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
String endereco,end,valor2 = null;
endereco = (janela1.getText());
InetAddress endip = null;
String [] valor;
try{
//endip = InetAddress.getByName(endereco);
endip = InetAddress.getByName(endereco);
end = String.valueOf(endip);
valor=end.split("/");
valor2=valor[1];
}
catch (UnknownHostException e){
}
janela2.setText(valor2);
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
janela1.setText("");
janela2.setText("");
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jButton4ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Apresentação().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JTextField janela1;
private javax.swing.JTextField janela2;
// End of variables declaration//GEN-END:variables
}
Um pouco de Java e Sockets. (Fonte 04: Main)
Comunicação através de datagramas
Nome da máquina e o endereço IP sem socket.
Um pouco de Java e Sockets. (Fonte 01: AbstractTransfer)
Nenhum comentário foi encontrado.
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Novos apps de produtividade, avanços em IA e distros em ebulição agitam o universo Linux
Como instalar o repositório do DBeaver no Ubuntu
Como instalar o Plex Media Server no Ubuntu
Digitando underscore com "shift" + "barra de espaços"
Como ativar a lixeira e recuperar aquivos deletados em um servidor Linux
Como mudar o nome de dispositivos Bluetooth via linha de comando
How can I remove duplicate MSG files from my folders effectively? (0)
O programa assinador digital (0)
dpkg: erro: gatilho de arquivo duplicado chamado pelo arquivo de nome (6)









