Browse Source

获取ipv6信息修复

chengwb3 9 years ago
parent
commit
f95137fd23

BIN
wade-mobile-common/libs/wade-mobile-func.jar


+ 215 - 159
wade-mobile-func/src/com/wade/mobile/func/MobileInfo.java

@ -16,172 +16,228 @@ import android.telephony.TelephonyManager;
16 16

17 17
import com.ailk.common.data.IData;
18 18
import com.ailk.common.data.impl.DataMap;
19
import com.mashape.relocation.conn.util.InetAddressUtils;
19 20
import com.wade.mobile.frame.IWadeMobile;
20 21
import com.wade.mobile.frame.plugin.Plugin;
21 22
import com.wade.mobile.util.FuncConstant;
22 23
import com.wade.mobile.util.Messages;
23 24

25
public class MobileInfo extends Plugin {
26
    public String platform = "Android";
24 27

25
public class MobileInfo extends Plugin{
26
	public String platform = "Android";
27
	
28
	public MobileInfo(IWadeMobile wademobile) {
29
		super(wademobile);
30
	}
31
	
32
	public void getTerminalType(JSONArray params) throws Exception{
33
		callback("a");//终端类型为android
34
	}
35
	
36
	/**
37
	 * 获取系统信息
38
	 * @param key
39
	 * @return
40
	 * @throws Exception 
41
	 */
42
	public void getSysInfo(JSONArray params) throws Exception {
43
		if(params.length()<1){
44
			throw new Exception(Messages.EXCEPTION_PARAM);
45
		}
46
		String key = params.getString(0).toUpperCase();
47
		if(key.equals(FuncConstant.PLATFORM)){
48
			callback(this.getPlatform());
49
		}else if(key.equals(FuncConstant.IMEI)){
50
			callback(this.getImei());
51
		}else if(key.equals(FuncConstant.UUID)){
52
			callback(this.getUuid());
53
		}else if(key.equals(FuncConstant.SIMNUMBER)){
54
			callback(this.getSimNumber());
55
		}else if(key.equals(FuncConstant.IMSI)){
56
			callback(this.getImsi());
57
		}else if(key.equals(FuncConstant.OSVERSION)){
58
			callback(this.getOSVersion());
59
		}else if(key.equals(FuncConstant.SDKVERSION)){
60
			callback(this.getSDKVersion());
61
		}else if(key.equals(FuncConstant.TIMEZONEID)){
62
			callback(this.getTimeZoneID());
63
		}else if(key.equals(FuncConstant.MODEL)){
64
			callback(this.getModel());
65
		}else if(key.equals(FuncConstant.MANUFACTURER)){
66
			callback(this.getManufacturer());
67
		}else if(key.equals(FuncConstant.BRAND)){
28
    public MobileInfo(IWadeMobile wademobile) {
29
        super(wademobile);
30
    }
31

32
    public void getTerminalType(JSONArray params) throws Exception {
33
        callback("a");// 终端类型为android
34
    }
35

36
    /**
37
     * 获取系统信息
38
     * 
39
     * @param key
40
     * @return
41
     * @throws Exception
42
     */
43
    public void getSysInfo(JSONArray params) throws Exception {
44
        if (params.length() < 1) {
45
            throw new Exception(Messages.EXCEPTION_PARAM);
46
        }
47
        String key = params.getString(0).toUpperCase();
48
        if (key.equals(FuncConstant.PLATFORM)) {
49
            callback(this.getPlatform());
50
        }
51
        else if (key.equals(FuncConstant.IMEI)) {
52
            callback(this.getImei());
53
        }
54
        else if (key.equals(FuncConstant.UUID)) {
55
            callback(this.getUuid());
56
        }
57
        else if (key.equals(FuncConstant.SIMNUMBER)) {
58
            callback(this.getSimNumber());
59
        }
60
        else if (key.equals(FuncConstant.IMSI)) {
61
            callback(this.getImsi());
62
        }
63
        else if (key.equals(FuncConstant.OSVERSION)) {
64
            callback(this.getOSVersion());
65
        }
66
        else if (key.equals(FuncConstant.SDKVERSION)) {
67
            callback(this.getSDKVersion());
68
        }
69
        else if (key.equals(FuncConstant.TIMEZONEID)) {
70
            callback(this.getTimeZoneID());
71
        }
72
        else if (key.equals(FuncConstant.MODEL)) {
73
            callback(this.getModel());
74
        }
75
        else if (key.equals(FuncConstant.MANUFACTURER)) {
76
            callback(this.getManufacturer());
77
        }
78
        else if (key.equals(FuncConstant.BRAND)) {
68 79
            callback(this.getBrand());
69
        }else if(key.equals(FuncConstant.PRODUCTNAME)){
80
        }
81
        else if (key.equals(FuncConstant.PRODUCTNAME)) {
70 82
            callback(this.getProductName());
71
        }else if(key.equals(FuncConstant.ALL)){
72
		}else{
73
			callback(Messages.NO_INFO);
74
		}
75
	}
76
	public String getAll() throws SocketException{
77
		IData data = new DataMap();
78
		data.put(FuncConstant.PLATFORM, this.getPlatform());
79
		data.put(FuncConstant.IMEI, this.getImei());
80
		data.put(FuncConstant.UUID, this.getUuid());
81
		data.put(FuncConstant.SIMNUMBER, this.getSimNumber());
82
		data.put(FuncConstant.IMSI, this.getImsi());
83
		data.put(FuncConstant.OSVERSION, this.getOSVersion());
84
		data.put(FuncConstant.SDKVERSION, this.getSDKVersion());
85
		data.put(FuncConstant.TIMEZONEID, this.getTimeZoneID());
86
		data.put(FuncConstant.MODEL, this.getModel());
87
		data.put(FuncConstant.MANUFACTURER, this.getManufacturer());
88
		data.put(FuncConstant.MAC, this.getMac());
89
		data.put(FuncConstant.IP, this.getIP());
90
		data.put(FuncConstant.BRAND, this.getBrand());
91
		return data.toString();
92
	}
93
	
94
	public String getPlatform()	{
95
		return platform;
96
	}
97
	
98
	public String getUuid()	{		
99
		String uuid = Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
100
		return uuid;
101
	}
102
	
103
	public String getTelNumber() {
104
		TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
105
		return manager.getLine1Number();
106
	}
107
	
108
	public String getImei() {
109
		TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
110
		return manager.getDeviceId();
111
	}
112
	
113
	public String getSimNumber() {
114
		TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
115
		return manager.getSimSerialNumber();
116
	}
117
	
118
	public String getImsi() {
119
		TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
120
		return manager.getSubscriberId();
121
	}
122
	
123
	public String getOSVersion() {
124
		String osversion = android.os.Build.VERSION.RELEASE;
125
		return osversion;
126
	}
127
	
128
	public String getSDKVersion() {
129
		String sdkversion = android.os.Build.VERSION.SDK;
130
		return sdkversion;
131
	}
132

133
	public String getTimeZoneID() {
134
		TimeZone tz = TimeZone.getDefault();
135
		return (tz.getID());
136
	}
137
	
138
	public String getManufacturer(){
139
		String manufacturer = android.os.Build.MANUFACTURER;
140
		return manufacturer;
141
	}
142
	public String getBrand(){
143
		String brand = android.os.Build.BRAND;
144
		return brand;
145
	}
146
	public String getModel() {
147
		String model = android.os.Build.MODEL;
148
		return model;
149
	}
150

151
	public String getProductName() {
152
		String productname = android.os.Build.PRODUCT;
153
		return productname;
154
	}
155
	
156
	/*****************network*************************/
157
	public void getNetInfo(JSONArray params) throws Exception {
158
		if(params.length()<1){
159
			throw new Exception(Messages.EXCEPTION_PARAM);
160
		}
161
		String key = params.getString(0).toUpperCase();
162
		if(key.equals(FuncConstant.MAC)){
163
			callback(getMac());
164
		}else if(key.equals(FuncConstant.IP)){
165
			callback(getIP());
166
		}
167
	}
168
	
169
	public String getMac() {   
170
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);   
171
        WifiInfo info = wifi.getConnectionInfo();   
172
        return info.getMacAddress();   
173
    }
174
	
175
	public String getIP() throws SocketException {   
176
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){   
177
            NetworkInterface intf = en.nextElement();   
178
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {   
179
                InetAddress inetAddress = enumIpAddr.nextElement();   
180
                if (!inetAddress.isLoopbackAddress()) {   
181
                    return inetAddress.getHostAddress().toString();   
182
                }   
183
            }   
184
        }   
185
        return null;   
83
        }
84
        else if (key.equals(FuncConstant.ALL)) {
85
            callback(this.getAll());
86
        }
87
        else {
88
            callback(Messages.NO_INFO);
89
        }
90
    }
91

92
    public String getAll() throws SocketException {
93
        IData data = new DataMap();
94
        data.put(FuncConstant.PLATFORM, this.getPlatform());
95
        data.put(FuncConstant.IMEI, this.getImei());
96
        data.put(FuncConstant.UUID, this.getUuid());
97
        data.put(FuncConstant.SIMNUMBER, this.getSimNumber());
98
        data.put(FuncConstant.IMSI, this.getImsi());
99
        data.put(FuncConstant.OSVERSION, this.getOSVersion());
100
        data.put(FuncConstant.SDKVERSION, this.getSDKVersion());
101
        data.put(FuncConstant.TIMEZONEID, this.getTimeZoneID());
102
        data.put(FuncConstant.MODEL, this.getModel());
103
        data.put(FuncConstant.MANUFACTURER, this.getManufacturer());
104
        data.put(FuncConstant.MAC, this.getMac());
105
        data.put(FuncConstant.IP, this.getIP());
106
        data.put(FuncConstant.IPV6, this.getIPV6());
107
        data.put(FuncConstant.BRAND, this.getBrand());
108
        data.put(FuncConstant.PRODUCTNAME, this.getProductName());
109
        return data.toString();
110
    }
111

112
    public String getPlatform() {
113
        return platform;
114
    }
115

116
    public String getUuid() {
117
        String uuid = Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
118
        return uuid;
119
    }
120

121
    public String getTelNumber() {
122
        TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
123
        return manager.getLine1Number();
124
    }
125

126
    public String getImei() {
127
        TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
128
        return manager.getDeviceId();
129
    }
130

131
    public String getSimNumber() {
132
        TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
133
        return manager.getSimSerialNumber();
134
    }
135

136
    public String getImsi() {
137
        TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
138
        return manager.getSubscriberId();
139
    }
140

141
    public String getOSVersion() {
142
        String osversion = android.os.Build.VERSION.RELEASE;
143
        return osversion;
144
    }
145

146
    public String getSDKVersion() {
147
        String sdkversion = android.os.Build.VERSION.SDK;
148
        return sdkversion;
149
    }
150

151
    public String getTimeZoneID() {
152
        TimeZone tz = TimeZone.getDefault();
153
        return (tz.getID());
154
    }
155

156
    public String getManufacturer() {
157
        String manufacturer = android.os.Build.MANUFACTURER;
158
        return manufacturer;
159
    }
160

161
    public String getBrand() {
162
        String brand = android.os.Build.BRAND;
163
        return brand;
164
    }
165

166
    public String getModel() {
167
        String model = android.os.Build.MODEL;
168
        return model;
169
    }
170

171
    public String getProductName() {
172
        String productname = android.os.Build.PRODUCT;
173
        return productname;
186 174
    }
175

176
    /***************** network *************************/
177
    public void getNetInfo(JSONArray params) throws Exception {
178
        if (params.length() < 1) {
179
            throw new Exception(Messages.EXCEPTION_PARAM);
180
        }
181
        String key = params.getString(0).toUpperCase();
182
        if (key.equals(FuncConstant.MAC)) {
183
            callback(getMac());
184
        }
185
        else if (key.equals(FuncConstant.IP)) {
186
            callback(getIP());
187
        }
188
        else if (key.equals(FuncConstant.IPV4)) {
189
            callback(getIPV4());
190
        }
191
        else if (key.equals(FuncConstant.IPV6)) {
192
            callback(getIPV6());
193
        }
194
    }
195

196
    public String getMac() {
197
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
198
        WifiInfo info = wifi.getConnectionInfo();
199
        return info.getMacAddress();
200
    }
201

202
    public String getIP() throws SocketException {
203
        return getIPV4();
204
    }
205

206
    /**
207
     * 获取IPV6地址
208
     */
209
    public String getIPV6() throws SocketException {
210
        String ipv6 = null;
211
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
212
            NetworkInterface intf = en.nextElement();
213
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
214
                InetAddress inetAddress = enumIpAddr.nextElement();
215
                String ipv6s = inetAddress.getHostAddress();
216
                if (ipv6s.contains("::") && ipv6s.contains("%")) {
217
                    ipv6 = ipv6s.substring(0, ipv6s.indexOf("%"));
218
                    if (InetAddressUtils.isIPv6Address(ipv6)) {
219
                        return ipv6;
220
                    }
221
                }
222
            }
223
        }
224
        return null;
225
    }
226
    
227
    /**
228
     * 获取IPV4地址
229
     */
230
    public String getIPV4() throws SocketException {
231
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
232
            NetworkInterface intf = en.nextElement();
233
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
234
                InetAddress inetAddress = enumIpAddr.nextElement();
235
                if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
236
                    return inetAddress.getHostAddress().toString();
237
                }
238
            }
239
        }
240
        return null;
241
    }
242

187 243
}

+ 2 - 0
wade-mobile-func/src/com/wade/mobile/util/FuncConstant.java

@ -17,6 +17,8 @@ public class FuncConstant {
17 17

18 18
	public static final String MAC = "MAC";
19 19
	public static final String IP = "IP";
20
	public static final String IPV4 = "IPV4";
21
	public static final String IPV6 = "IPV6";
20 22
	
21 23
	public static final String CONTENT = "CONTENT";
22 24
	public static final String SENDER = "SENDER";