18 lines
393 B
Dart
18 lines
393 B
Dart
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
|
|
Future<String> getPublicIPAddress() async {
|
|
try {
|
|
var response =
|
|
await http.get(Uri.parse('https://api.ipify.org/?format=json'));
|
|
if (response.statusCode == 200) {
|
|
var data = json.decode(response.body);
|
|
return data['ip'];
|
|
}
|
|
} catch (e) {
|
|
print(e.toString());
|
|
}
|
|
return '127.0.0.1';
|
|
}
|