Skip to content

Instantly share code, notes, and snippets.

@4anonz
Created November 12, 2021 01:12
Show Gist options
  • Save 4anonz/0137b261ba1bcdf35b5d6f6f3c950875 to your computer and use it in GitHub Desktop.
Save 4anonz/0137b261ba1bcdf35b5d6f6f3c950875 to your computer and use it in GitHub Desktop.
IP lookup program with GUI in java
import java.awt.*;
import java.awt.event.*;
class IPLookup implements ActionListener {
Label label;
TextField text;
IPLookup() {
Frame frame = new Frame("IP Lookup");
Button button = new Button("Find IP");
label = new Label();
text = new TextField();
text.setBounds(30, 40, 300, 30);
button.setBounds(30, 70, 120, 30);
label.setBounds(30, 100, 600, 30);
button.addActionListener(this);
frame.add(text);
frame.add(label);
frame.add(button);
frame.setSize(400, 520);
frame.setLayout(null);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
String host = text.getText();
String ip = java.net.InetAddress.getByName(host).getHostAddress();
label.setText(host + " resolved to: "+ ip);
}
catch(Exception ex) {
System.out.println(ex);
}
}
public static void main(String[] args) {
new IPLookup();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment