]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | |
2 | import java.awt.*; | |
3 | import java.awt.event.*; | |
4 | import javax.swing.*; | |
5 | import java.net.URL; | |
6 | import java.net.*; | |
7 | import java.io.*; | |
8 | import com.easysw.cups.*; | |
9 | ||
10 | public class GLPsearch extends Thread | |
11 | { | |
12 | String localHostName = null; | |
13 | String localHostIP = null; | |
14 | String localSubNet = null; | |
15 | InetAddress localHostAddress = null; | |
16 | ||
17 | private int current_octet = 1; | |
18 | private int count = 0; | |
19 | private int thread_num = 0; | |
20 | private boolean is_done = false; | |
21 | private boolean is_completed = false; | |
22 | ||
23 | ||
24 | // Constructor | |
25 | public GLPsearch( int t_num ) | |
26 | { | |
27 | thread_num = t_num; | |
28 | try | |
29 | { | |
30 | localHostAddress = InetAddress.getLocalHost(); | |
31 | } | |
32 | catch (UnknownHostException e) | |
33 | { | |
34 | } | |
35 | localHostName = localHostAddress.getHostName(); | |
36 | // localHostIP = localHostAddress.getHostAddress(); | |
37 | localHostIP = "192.168.1.100"; | |
38 | int i = localHostIP.lastIndexOf("."); | |
39 | localSubNet = localHostIP.substring(0,i); | |
40 | } | |
41 | ||
42 | ||
43 | ||
44 | // Constructor | |
45 | public GLPsearch(int t_num, String subnet) | |
46 | { | |
47 | thread_num = t_num; | |
48 | try | |
49 | { | |
50 | localHostAddress = InetAddress.getLocalHost(); | |
51 | } | |
52 | catch (UnknownHostException e) | |
53 | { | |
54 | } | |
55 | localHostName = localHostAddress.getHostName(); | |
56 | localHostIP = localHostAddress.getHostAddress(); | |
57 | localSubNet = subnet; | |
58 | } | |
59 | ||
60 | ||
61 | public void run() | |
62 | { | |
63 | Cups cups = null; | |
64 | String host = ""; | |
65 | String test = ""; | |
66 | InetAddress lookupAddress; | |
67 | URL u = null; | |
68 | ||
69 | is_done = false; | |
70 | for (int x = thread_num+1; x < 255 && !is_done; x += 8 ) | |
71 | { | |
72 | count++; | |
73 | current_octet = x; | |
74 | host = localSubNet + "." + x; | |
75 | try | |
76 | { | |
77 | u = new URL("http://" + host + ":631/printers"); | |
78 | cups = new Cups(u); | |
79 | cups.setUser(GLPvars.cupsUser); | |
80 | cups.setPasswd(GLPvars.cupsPasswd); | |
81 | ||
82 | test = cups.cupsGetDefault(); | |
83 | if ((test != null) && (test.length() > 0)) | |
84 | { | |
85 | lookupAddress = InetAddress.getByName(host); | |
86 | GLPvars.addToServerList(lookupAddress.getHostName()); | |
87 | } | |
88 | else | |
89 | { | |
90 | } | |
91 | } | |
92 | catch (IOException e) | |
93 | { | |
94 | } | |
95 | } | |
96 | if (!is_done) | |
97 | is_completed = true; | |
98 | is_done = true; | |
99 | } | |
100 | ||
101 | public void interrupt() | |
102 | { | |
103 | is_done = true; | |
104 | } | |
105 | ||
106 | public boolean completed() | |
107 | { | |
108 | return(is_completed); | |
109 | } | |
110 | ||
111 | public boolean done() | |
112 | { | |
113 | return(is_done); | |
114 | } | |
115 | ||
116 | public int getValue() | |
117 | { | |
118 | return(count); | |
119 | } | |
120 | ||
121 | } |