nome para ip & ip para nome com ping
Publicado por Abraao dos Santos Carvalho 03/10/2007
[ Hits: 7.165 ]
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 }
Nome da máquina e o endereço IP sem socket.
Nenhum comentário foi encontrado.
Compartilhando a tela do Computador no Celular via Deskreen
Como Configurar um Túnel SSH Reverso para Acessar Sua Máquina Local a Partir de uma Máquina Remota
Configuração para desligamento automatizado de Computadores em um Ambiente Comercial
Como renomear arquivos de letras maiúsculas para minúsculas
Imprimindo no formato livreto no Linux
Vim - incrementando números em substituição
Efeito "livro" em arquivos PDF
Como resolver o erro no CUPS: Unable to get list of printer drivers
Vou voltar moderar conteúdos de Dicas e Artigos (2)
Melhorando a precisão de valores flutuantes em python[AJUDA] (8)
[Python] Automação de scan de vulnerabilidades
[Python] Script para analise de superficie de ataque
[Shell Script] Novo script para redimensionar, rotacionar, converter e espelhar arquivos de imagem
[Shell Script] Iniciador de DOOM (DSDA-DOOM, Doom Retro ou Woof!)
[Shell Script] Script para adicionar bordas às imagens de uma pasta