-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathIPResponse.java
More file actions
222 lines (189 loc) · 5.32 KB
/
IPResponse.java
File metadata and controls
222 lines (189 loc) · 5.32 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package io.ipinfo.api.model;
import io.ipinfo.api.context.Context;
public class IPResponse {
private final String ip;
private final String hostname;
private final boolean bogon;
// IPinfo's IP response indicates whether an IP is anycast, using either
// `anycast` or `is_anycast` fields, depending on the token's capabilities.
private final boolean anycast;
private final boolean is_anycast;
private final String city;
private final String region;
private final String country;
private final String loc;
private final String org;
private final String postal;
private final String timezone;
private final ASN asn;
private final Company company;
private final Carrier carrier;
private final Privacy privacy;
private final Abuse abuse;
private final Domains domains;
private transient Context context;
public IPResponse(
String ip,
String hostname,
boolean bogon,
boolean anycast,
boolean is_anycast,
String city,
String region,
String country,
String loc,
String org,
String postal,
String timezone,
ASN asn,
Company company,
Carrier carrier,
Privacy privacy,
Abuse abuse,
Domains domains
) {
this.ip = ip;
this.hostname = hostname;
this.bogon = bogon;
this.anycast = anycast;
this.is_anycast = is_anycast;
this.city = city;
this.region = region;
this.country = country;
this.loc = loc;
this.postal = postal;
this.timezone = timezone;
this.org = org;
this.asn = asn;
this.company = company;
this.carrier = carrier;
this.privacy = privacy;
this.abuse = abuse;
this.domains = domains;
}
public IPResponse(
String ip,
boolean bogon
) {
this(ip, null, bogon, false, false, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
/**
* Set by the library for extra utility functions
*
* @param context for country information
*/
public void setContext(Context context) {
this.context = context;
}
public String getIp() {
return ip;
}
public String getHostname() {
return hostname;
}
public boolean getBogon() {
return bogon;
}
public boolean getAnycast() {
return anycast || is_anycast;
}
public String getCity() {
return city;
}
public String getRegion() {
return region;
}
public String getCountryCode() {
return country;
}
public String getCountryName() {
return context.getCountryName(getCountryCode());
}
public Boolean isEU() {
return context.isEU(getCountryCode());
}
public CountryFlag getCountryFlag() {
return context.getCountryFlag(getCountryCode());
}
public String getCountryFlagURL() {
return context.getCountryFlagURL(getCountryCode());
}
public CountryCurrency getCountryCurrency() {
return context.getCountryCurrency(getCountryCode());
}
public Continent getContinent() {
return context.getContinent(getCountryCode());
}
public String getLocation() {
return loc;
}
public String getLatitude() {
try {
return loc.split(",")[0];
} catch (Exception ex) {
return null;
}
}
public String getLongitude() {
try {
return loc.split(",")[1];
} catch (Exception ex) {
return null;
}
}
public String getOrg() {
return org;
}
public String getPostal() {
return postal;
}
public String getTimezone() {
return timezone;
}
public ASN getAsn() {
return asn;
}
public Company getCompany() {
return company;
}
public Carrier getCarrier() {
return carrier;
}
public Privacy getPrivacy() {
return privacy;
}
public Abuse getAbuse() {
return abuse;
}
public Domains getDomains() {
return domains;
}
@Override
public String toString() {
return (bogon ?
"IPResponse{" +
"ip='" + ip + '\'' +
", bogon='" + bogon + '\'' +
"}"
:
"IPResponse{" +
"ip='" + ip + '\'' +
", hostname='" + hostname + '\'' +
", anycast=" + anycast +
", is_anycast=" + is_anycast +
", city='" + city + '\'' +
", region='" + region + '\'' +
", country='" + country + '\'' +
", loc='" + loc + '\'' +
", org='" + org + '\'' +
", postal='" + postal + '\'' +
", timezone='" + timezone + '\'' +
", asn=" + asn +
", company=" + company +
", carrier=" + carrier +
", privacy=" + privacy +
", abuse=" + abuse +
", domains=" + domains +
'}');
}
}