⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.java

📁 sifi-0.1.6.tar.gz 出自http://www.ifi.unizh.ch/ikm/SINUS/firewall/ 一个linux的防火墙工具。
💻 JAVA
字号:
/* ----------------------------------------------------------------------   The SINUS Firewall -- a TCP/IP packet filter for Linux   Written within the SINUS project at the University of Zurich,   SWITCH, Telekurs Payserv AG, ETH Zurich.   originally based on the sf Firewall Software (C) 1996 by Robert   Muchsel and Roland Schmid.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   SINUS Firewall resources:   SINUS Homepage: http://www.ifi.unizh.ch/ikm/SINUS/   Firewall Homepage: http://www.ifi.unizh.ch/ikm/SINUS/firewall.html   Frequently asked questions: http://www.ifi.unizh.ch/ikm/SINUS/sf_faq.html   Mailing list for comments, questions, bug reports: firewall@ifi.unizh.ch   ----------------------------------------------------------------------  */package sfclasses;import java.awt.*;import java.util.*;/** * Collection of utility routines * @version 1.0 07 Jan 1997 * @author Roland E. Schmid */public class Utils {  /**   * Prepare component to be added using GridBagLayout   */  public static void add_component(Container cont, Component c,                                    GridBagLayout gbl, GridBagConstraints gbc,                                   int x, int y, int w, int h, int wx, int wy) {    gbc.gridx = x;    gbc.gridy = y;    gbc.gridwidth = w;    gbc.gridheight = h;    gbc.weightx = wx;    gbc.weighty = wy;    gbl.setConstraints(c, gbc);    cont.add(c);  }  /**   * Execute getParent() repeatedly until it finds the parent frame   * @param pcomp Component   * @return parent frame   */  public static Frame getParentFrame(Component pcomp) {    Component parent = pcomp;    while ((parent != null) && !(parent instanceof Frame)) {      parent = parent.getParent();    }    if (parent == null)      return null;    else      return (Frame)parent;  }  /**   * Construct system dependent prefix for file URLs   */  public static String fileURLPrefix() {    String osName = System.getProperty("os.name");    if (osName.equals("OS/2") || osName.equals("Windows 95")) // IBM needs an extra slash      return "file:///";    return "file://"; // default, works fine on UNIX systems  }  /**   * Parse string of the form xxx.xxx.xxx.xxx and return an IP   * address in byte array format.   */  public static byte[] parseIP(String addr) throws IllegalArgumentException {    byte[] tempaddr = new byte[4];    String ts;    int ti;    StringTokenizer st = new StringTokenizer(addr, ".");    if (st.countTokens() != 4)      throw new IllegalArgumentException();    for (int i = 0; i<4 ; i++) {      ts = st.nextToken();      try {        ti = Integer.parseInt(ts);      }      catch (NumberFormatException e) {        throw new IllegalArgumentException();      }      if (ti >= 256 || ti < 0)        throw new IllegalArgumentException();      tempaddr[i] = (byte)ti;    }    return tempaddr;  }  /**   * Print an IP address given in byte array format.   * @return String containing the IP address xxx.xxx.xxx.xxx   */  public static String printIP(byte[] addr) {    if (addr == null || addr.length != 4)      return "";    StringBuffer sb = new StringBuffer(15);    for (int i=0; i<4; i++) {      sb.append(unsign(addr[i]));      if (i<3)        sb.append('.');    }    return sb.toString();  }  /**   * @return Unsigned value of a byte variable (0..255)   */  public static long unsign(byte i) {    if (i<0)      return (long)i + 256;    else      return (long)i;  }  /**   * @return Unsigned value of a short variable (0..65535)   */  public static long unsign(short i) {    if (i<0)      return (long)i + 65536;    else      return (long)i;  }  /**   * @return Unsigned value of an int variable (0..2^32-1)   */  public static long unsign(int i) {    if (i<0)      return (long)i + 2*(Integer.MAX_VALUE + 1);    else      return (long)i;  }  /**   * @return String containing only the time from Date.toString()   * @param d Date object   */  public static String timeString(Date d) {    String tstr = d.toString();    return tstr.substring(tstr.indexOf(':')-2,tstr.indexOf(':')+6);  }  /**   * @return Red ball icon   */  public static Image redBall() {    if (redBallSource == null)      redBallSource = new redballImageSource();    return Toolkit.getDefaultToolkit().createImage(redBallSource);  }  /**   * @return Green ball icon   */  public static Image greenBall() {    if (greenBallSource == null)      greenBallSource = new greenballImageSource();    return Toolkit.getDefaultToolkit().createImage(greenBallSource);  }  /**   * @return Yellow ball icon   */  public static Image yellowBall() {    if (yellowBallSource == null)      yellowBallSource = new yellowballImageSource();    return Toolkit.getDefaultToolkit().createImage(yellowBallSource);  }  private static java.awt.image.ImageProducer redBallSource = null;  private static java.awt.image.ImageProducer greenBallSource = null;  private static java.awt.image.ImageProducer yellowBallSource = null;}class redballImageSource extends java.awt.image.MemoryImageSource {  final static int bWidth = 12;  final static int bHeight = 12;  private static int[] bPixels = { // color model is AARRGGBB    0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xffc67b8c, 0xffce426b,     0xffce104a, 0xffce104a, 0xffce426b, 0xffc67b8c, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffce637b, 0xffd60042, 0xffff0052,     0xffff0052, 0xffff004a, 0xffef0042, 0xffc60039, 0xffce637b,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xffc67b94, 0xffce0039, 0xffff0052, 0xffff105a,     0xffff317b, 0xffff0852, 0xffe70042, 0xffc60039, 0xff9c0029,     0xffc67b94, 0x00bfbfbf,     0x00bfbfbf, 0xffce426b, 0xffff0052, 0xffff0852, 0xffff8cd6,     0xffffa5ef, 0xffff1052, 0xffd60042, 0xffbd0039, 0xff940029,     0xff841031, 0x00bfbfbf,     0x00bfbfbf, 0xffce104a, 0xffff004a, 0xffff0852, 0xffff317b,     0xffff2163, 0xffd60842, 0xffbd0039, 0xff9c0029, 0xff840029,     0xff5a0018, 0x00bfbfbf,     0x00bfbfbf, 0xffce104a, 0xffde0042, 0xffe70042, 0xffde0042,     0xffce0039, 0xffb50031, 0xff9c0029, 0xff840029, 0xff630018,     0xff5a0018, 0x00bfbfbf,     0x00bfbfbf, 0xffce426b, 0xffbd0039, 0xffbd0039, 0xffbd0031,     0xffad0031, 0xff9c0029, 0xff840029, 0xff5a0021, 0xff4a0018,     0xff731031, 0xffc6bdbd,     0x00bfbfbf, 0xffc67b94, 0xff940029, 0xff9c0029, 0xff940029,     0xff840029, 0xff730021, 0xff630018, 0xff4a0010, 0xff4a0018,     0xff9c4a63, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffce6384, 0xff6b0021, 0xff6b0021,     0xff5a0018, 0xff4a0018, 0xff4a0018, 0xff4a0018, 0xff8c314a,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xffc6bdbd, 0x00bfbfbf, 0xffc67b94, 0xff731031,     0xff5a0018, 0xff5a0018, 0xff731031, 0xff9c4a63, 0xffc6bdbd,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xffc6bdbd, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffc6bdbd, 0x00bfbfbf, 0x00bfbfbf,     0xffc6bdbd, 0x00bfbfbf,     };  public redballImageSource() {    super( bWidth, bHeight, bPixels, 0, bWidth );  }}class greenballImageSource extends java.awt.image.MemoryImageSource {  final static int bWidth = 12;  final static int bHeight = 12;  private static int[] bPixels = { // color model is AARRGGBB    0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xff5cb898, 0xff32cd32,     0xff32cd32, 0xff32cd32, 0xff32cd32, 0xff5cb898, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xff5cb898, 0xff00ff00, 0xff00ff00,     0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff32cd32, 0xff5cb898,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xff5cb898, 0xff32cd32, 0xff00ff00, 0xff00ff00,     0xff32cd32, 0xff00ff00, 0xff00ff00, 0xff32cd32, 0xff228b22,     0xff5cb898, 0x00bfbfbf,     0x00bfbfbf, 0xff32cd32, 0xff00ff00, 0xff00ff00, 0xff98fb98,     0xff98fb98, 0xff00ff00, 0xff00ff00, 0xff32cd32, 0xff228b22,     0xff228b22, 0x00bfbfbf,     0x00bfbfbf, 0xff32cd32, 0xff00ff00, 0xff00ff00, 0xff32cd32,     0xff32cd32, 0xff32cd32, 0xff32cd32, 0xff228b22, 0xff006400,     0xff006400, 0x00bfbfbf,     0x00bfbfbf, 0xff32cd32, 0xff00ff00, 0xff00ff00, 0xff00ff00,     0xff32cd32, 0xff228b22, 0xff228b22, 0xff006400, 0xff006400,     0xff006400, 0x00bfbfbf,     0x00bfbfbf, 0xff32cd32, 0xff32cd32, 0xff32cd32, 0xff32cd32,     0xff228b22, 0xff228b22, 0xff006400, 0xff006400, 0xff006400,     0xff228b22, 0xffc2c2c2,     0x00bfbfbf, 0xff5cb898, 0xff228b22, 0xff228b22, 0xff228b22,     0xff006400, 0xff006400, 0xff006400, 0xff006400, 0xff006400,     0xff2e8b57, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xff5cb898, 0xff006400, 0xff006400,     0xff006400, 0xff006400, 0xff006400, 0xff006400, 0xff2e8b57,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xffc2c2c2, 0x00bfbfbf, 0xff5cb898, 0xff228b22,     0xff006400, 0xff006400, 0xff228b22, 0xff2e8b57, 0xffc2c2c2,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xffc2c2c2, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffc2c2c2, 0x00bfbfbf, 0x00bfbfbf,     0xffc2c2c2, 0x00bfbfbf,     };  public greenballImageSource() {    super( bWidth, bHeight, bPixels, 0, bWidth );  }}class yellowballImageSource extends java.awt.image.MemoryImageSource {  final static int bWidth = 12;  final static int bHeight = 12;  private static int[] bPixels = { // color model is AARRGGBB    0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xffc2c67b, 0xffccce42,     0xffcece10, 0xffcece10, 0xffccce42, 0xffc2c67b, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffc9ce63, 0xffd6d600, 0xffffff00,     0xffffff00, 0xfffbff00, 0xffe7ef00, 0xffc3c600, 0xffc9ce63,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xffc6c67b, 0xffc7ce00, 0xffffff00, 0xffffff10,     0xfffffc31, 0xfffbff08, 0xffe3e700, 0xffc3c600, 0xff979c00,     0xffc6c67b, 0x00bfbfbf,     0x00bfbfbf, 0xffccce42, 0xffffff00, 0xfffbff08, 0xffffea8c,     0xffffe4a5, 0xfff7ff10, 0xffd6d600, 0xffbdbd00, 0xff8f9400,     0xff828410, 0x00bfbfbf,     0x00bfbfbf, 0xffcece10, 0xfffbff00, 0xfffbff08, 0xfffffc31,     0xfffbff21, 0xffcfd608, 0xffbdbd00, 0xff979c00, 0xff848400,     0xff575a00, 0x00bfbfbf,     0x00bfbfbf, 0xffcece10, 0xffdade00, 0xffe3e700, 0xffdade00,     0xffc7ce00, 0xffafb500, 0xff979c00, 0xff848400, 0xff5e6300,     0xff575a00, 0x00bfbfbf,     0x00bfbfbf, 0xffccce42, 0xffbdbd00, 0xffbdbd00, 0xffb7bd00,     0xffa7ad00, 0xff979c00, 0xff848400, 0xff5a5900, 0xff4a4a00,     0xff737310, 0xffc4c6bd,     0x00bfbfbf, 0xffc6c67b, 0xff8f9400, 0xff979c00, 0xff8f9400,     0xff848400, 0xff717300, 0xff5e6300, 0xff454a00, 0xff4a4a00,     0xff9c9c4a, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffcece63, 0xff6b6b00, 0xff6b6b00,     0xff575a00, 0xff4a4a00, 0xff4a4a00, 0xff4a4a00, 0xff898c31,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0xffc4c6bd, 0x00bfbfbf, 0xffc6c67b, 0xff737310,     0xff575a00, 0xff575a00, 0xff737310, 0xff9c9c4a, 0xffc4c6bd,     0x00bfbfbf, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0x00bfbfbf, 0xffc4c6bd, 0x00bfbfbf,     0x00bfbfbf, 0x00bfbfbf, 0xffc4c6bd, 0x00bfbfbf, 0x00bfbfbf,     0xffc4c6bd, 0x00bfbfbf,     };  public yellowballImageSource() {    super( bWidth, bHeight, bPixels, 0, bWidth );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -