-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
154 lines (140 loc) · 4.71 KB
/
App.js
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useEffect, useState } from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
} from 'react-native';
import {Appearance} from 'react-native';
import { NetworkInfo } from "react-native-network-info";
import {Config} from 'react-native-config';
import Geolocation from '@react-native-community/geolocation'
const App = () => {
const colorScheme = Appearance.getColorScheme();
const [SSID, setSSID] = useState("Loading...")
const [publicIP, setPublicIP] = useState("Loading...")
const [privateIP, setPrivateIP] = useState("Loading...")
const [gateway, setGateway] = useState("Loading...")
const [ISP, setISP] = useState("Loading...")
const fetchSSID = () => {
NetworkInfo.getSSID().then(_ssid => {
setSSID(_ssid || "Unavailable")
}).catch(err => {
setSSID("Unavailable")
});
}
useEffect(() => {
Geolocation.requestAuthorization();
fetchSSID();
fetch("https://api.ipify.org/?format=json")
.then(res => res.json())
.then(json => {
setPublicIP(json.ip || "Unavailable")
fetch(`https://ipinfo.io/${json.ip}/json?token=${Config.IPINFO_TOKEN}`)
.then(res => res.json())
.then(json => {
setISP(json.org || "Unavailable")
}).catch(err => {
setISP("Unavailable")
})
}).catch(err => {
setPublicIP("Unavailable")
})
NetworkInfo.getIPAddress().then(ipv4Address => {
setPrivateIP(ipv4Address || "Unavailable");
}).catch(err => {
setPrivateIP("Unavailable")
});
NetworkInfo.getGatewayIPAddress().then(defaultGatewayIP => {
setGateway(defaultGatewayIP || "Unavailable");
}).catch(err => {
setGateway("Unavailable")
});
}, []);
return (
<>
<StatusBar barStyle={colorScheme === 'dark' ? "light-content" : "dark-content"}/>
<SafeAreaView style={colorScheme === 'dark' ? styles.darkContainer : styles.lightContainer}>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.container}>
<Text style={[styles.headerText, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Internetty</Text>
<Text style={[styles.subtitleText, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Here's your Internet details:</Text>
<View style={styles.detailsView}>
<View style={styles.detailView}>
<Text style={[styles.detailValue, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>{SSID}</Text>
<Text style={[styles.detail, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Network SSID</Text>
</View>
<View style={styles.detailView}>
<Text style={[styles.detailValue, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>{publicIP}</Text>
<Text style={[styles.detail, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Public IP address</Text>
</View>
<View style={styles.detailView}>
<Text style={[styles.detailValue, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>{privateIP}</Text>
<Text style={[styles.detail, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Local IP address</Text>
</View>
<View style={styles.detailView}>
<Text style={[styles.detailValue, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>{gateway}</Text>
<Text style={[styles.detail, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Default gateway</Text>
</View>
<View style={styles.detailView}>
<Text style={[styles.detailValue, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>{ISP}</Text>
<Text style={[styles.detail, colorScheme === 'dark' ? styles.lightText : styles.darkText]}>Internet service provider</Text>
</View>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
lightText: {
color: '#fff'
},
darkText: {
color: '#000'
},
darkContainer: {
backgroundColor: '#000',
color: '#fff'
},
lightContainer: {
backgroundColor: '#fff',
color: '#000'
},
container: {
textAlign: 'center',
padding: 50,
},
headerText: {
fontSize: 50,
fontWeight: '600'
},
subtitleText: {
fontSize: 25
},
detailsView: {
paddingTop: 20,
paddingBottom: 80
},
detailView: {
paddingTop: 50,
},
detailValue: {
fontWeight: '600',
fontSize: 35,
},
detail: {
fontSize: 20
}
});
export default App;