File: GLPsearch.java

package info (click to toggle)
cupsys 1.2.7-4%2Betch9
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,436 kB
  • ctags: 10,404
  • sloc: ansic: 97,130; cpp: 49,167; java: 6,199; sh: 4,723; makefile: 1,918; lisp: 232; perl: 145; python: 119; php: 28
file content (121 lines) | stat: -rw-r--r-- 2,791 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
import java.net.*;
import java.io.*;
import com.easysw.cups.*;

public class GLPsearch extends Thread
{
    String       localHostName      = null;
    String       localHostIP        = null;
    String       localSubNet        = null;
    InetAddress  localHostAddress   = null;

    private      int current_octet  = 1;
    private      int count          = 0;
    private      int thread_num     = 0;
    private      boolean is_done    = false;
    private      boolean is_completed  = false;
      

    // Constructor
    public GLPsearch( int t_num ) 
    {
      thread_num = t_num;
      try
      {
        localHostAddress = InetAddress.getLocalHost();
      }
      catch (UnknownHostException e)
      {
      }
      localHostName    = localHostAddress.getHostName();
      // localHostIP      = localHostAddress.getHostAddress();
      localHostIP = "192.168.1.100";
      int i = localHostIP.lastIndexOf(".");
      localSubNet      = localHostIP.substring(0,i);
    }



    // Constructor
    public GLPsearch(int t_num, String subnet) 
    {
      thread_num = t_num;
      try
      {
        localHostAddress = InetAddress.getLocalHost();
      }
      catch (UnknownHostException e)
      {
      }
      localHostName    = localHostAddress.getHostName();
      localHostIP      = localHostAddress.getHostAddress();
      localSubNet      = subnet;
    }


    public void run()
    {
        Cups   cups = null;
        String host = "";
        String test = "";
        InetAddress  lookupAddress;
        URL    u    = null;

        is_done = false;
        for (int x = thread_num+1; x < 255 && !is_done; x += 8 )
        {
           count++;
           current_octet = x;
           host = localSubNet + "." + x;
           try
           {
             u    = new URL("http://" + host + ":631/printers");
             cups = new Cups(u);
             cups.setUser(GLPvars.cupsUser);
             cups.setPasswd(GLPvars.cupsPasswd);

             test = cups.cupsGetDefault();
             if ((test != null) && (test.length() > 0))
             {
               lookupAddress = InetAddress.getByName(host);
               GLPvars.addToServerList(lookupAddress.getHostName());
             }
             else
             {
             }
           }
           catch (IOException e)
           {
           }
        }
        if (!is_done)
          is_completed = true;
        is_done = true;
    }

    public void interrupt()
    {
        is_done = true;
    }

    public boolean completed()
    {
        return(is_completed);
    }

    public boolean done()
    {
        return(is_done);
    }

    public int getValue()
    {
        return(count);
    }

}