
www.ethemsulan.com
By: a guest on Mar 6th, 2010 | syntax:
Java | size: 0.92 KB | hits: 462 | expires: Never
package www.ethemsulan.com;
import java.util.regex.PatternSyntaxException;
import javax.swing.JOptionPane;
public class IpV4Kontrolu {
public static void main(String[] args) {
try {
String girilenIp=JOptionPane.showInputDialog("Bir IpV4 adresi girin");
if (girilenIp.matches("\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b")) {
JOptionPane.showMessageDialog(null, girilenIp+" dogru IpV4 adresi girildi");
} else {
JOptionPane.showMessageDialog(null, girilenIp+" yanlış IpV4 adresi girildi");
}
} catch (PatternSyntaxException ex) {
ex.printStackTrace();
//127.0.0.1 dogru ipv4 localhost adresi
//299.299.299.299 yanlış 255 ten büyük olamaz.değerler her bir aralık
//255.255.255.256 yanlış max 255 olur.
//0:0:0:0:0:0:0:1 ipv6
//92.168.1.1 doğr ipv4 adresi
}
}
}