File: AirportHangup.java

package info (click to toggle)
airport-utils 2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,048 kB
  • sloc: java: 30,844; xml: 571; sh: 563; makefile: 10
file content (135 lines) | stat: -rw-r--r-- 3,123 bytes parent folder | download | duplicates (7)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * AirportHangup CLI Utility
 *
 * Copyright (C) 2001, Jonathan Sevy <jsevy@mcs.drexel.edu>
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */



import java.net.*;



public class AirportHangup
{
	
	InetAddress hostAddress;
			
	
	
	
	private static void hangupModem(InetAddress hostAddress) 
	{
		try
		{
			DatagramSocket dSocket = new DatagramSocket();
			dSocket.setSoTimeout(15000);	//15 seconds
			int AIRPORT_PORT = 192;
			
			byte[] bytes = new byte[116];	// from sniffs
			bytes[0] = (byte)0x06;			// from S. Sexton - thanks!
			
			DatagramPacket outPacket = new DatagramPacket(bytes, bytes.length, hostAddress, AIRPORT_PORT);
					
			dSocket.send(outPacket);	
					
		}
		catch(Exception e)
		{
			System.out.println("Exception during hangup:  " + e + "\n");
		}
		
	}
	
	
	
	private static void connectModem(InetAddress hostAddress) 
	{
		try
		{
			DatagramSocket dSocket = new DatagramSocket();
			dSocket.setSoTimeout(15000);	//15 seconds
			int AIRPORT_PORT = 192;
			
			byte[] bytes = new byte[116];	// from sniffs
			bytes[0] = (byte)0x07;			// from P. Werz - thanks!
			
			
			DatagramPacket outPacket = new DatagramPacket(bytes, bytes.length, hostAddress, AIRPORT_PORT);
					
			dSocket.send(outPacket);
				
		}
		catch(Exception e)
		{
			System.out.println("Exception during modem connect:  " + e + "\n");
		}
		
	}
	
	
	
	
	private static void printUsage()
	{
		System.out.println("Usage: java -jar AirportModemUtilityCLI.jar <IP address> <command>");
		System.out.println("   where <command> is C, c, Connect, connect");
		System.out.println("                   or H, h, Hangup, hangup");
	}
	
	
	
	
	public static void main(String args[]) 
	{
		try
		{
			// make sure have at least 2 args
			if (args.length < 2)
			{
				printUsage();
			}
			else
			{
				// base station address is argument 0
				InetAddress hostAddress = InetAddress.getByName(args[0]);
		
				// command is arg 1: "h", "H" for hangup, "c", "C" for connect
				String command = (args[1]).substring(0,1);
				if (command.equalsIgnoreCase("c"))
				{
					connectModem(hostAddress);
				}
				else if (command.equalsIgnoreCase("h"))
				{
					hangupModem(hostAddress);
				}
				else
				{
					printUsage();
				}
			}
		}
		catch (Exception e)
		{
			System.out.println("Exception:  " + e + "\n");
		}
	}
	

}