-
-
免费IPv6测试
+ <>
+
IPv6测试
-
-
-
IPv4 {http4?.address}
-
IPv6 {http6?.address}
-
-
- {/*
探索更多 */}
+
-
+ >
)
}
diff --git a/src/components/CheckItem.tsx b/src/components/CheckItem.tsx
new file mode 100644
index 0000000..9197552
--- /dev/null
+++ b/src/components/CheckItem.tsx
@@ -0,0 +1,50 @@
+import { CheckItemIconState, CheckItemType } from "@/types/CheckItem"
+import { Icon } from "@iconify/react/dist/iconify.js"
+import useSWRImmutable from "swr/immutable"
+
+type CheckItemProps = CheckItemType
+
+const fetcher = (url: string | URL | Request) =>
+ fetch(url).then((r) => r.json())
+
+const icon = {
+ ok: (
+
+ ),
+ loading:
,
+ info: (
+
+ ),
+ error: (
+
+ ),
+}
+
+export default function CheckItem({ url, content }: CheckItemProps) {
+ const { data, error, isLoading } = useSWRImmutable(url, fetcher)
+
+ return (
+ <>
+
+ {error
+ ? icon["error"]
+ : isLoading
+ ? icon["loading"]
+ : data != undefined
+ ? icon[content(data).state]
+ : null}
+
+ {data != undefined ? {content(data).text} : null}
+
+ >
+ )
+}
diff --git a/src/components/Checker.tsx b/src/components/Checker.tsx
new file mode 100644
index 0000000..df2c997
--- /dev/null
+++ b/src/components/Checker.tsx
@@ -0,0 +1,35 @@
+import CheckItem from "./CheckItem"
+import { CheckItemType } from "@/types/CheckItem"
+
+const checkList: CheckItemType[] = [
+ {
+ url: "https://6.ipv6test.online/ip/myip",
+ content: (data) => {
+ const isIPv6 = data?.version == 6
+ return {
+ state: isIPv6 ? "ok" : "error",
+ text: "公网 IPv6 地址: " + (isIPv6 ? `${data?.address}` : "未检测到")
+ }
+ },
+ },
+ {
+ url: "https://4.ipv6test.online/ip/myip",
+ content: (data) => {
+ const isIPv4 = data?.version == 4
+ return {
+ state: isIPv4 ? "ok" : "error",
+ text: "公网 IPv4 地址: " + (isIPv4 ? `${data?.address}` : "未检测到")
+ }
+ },
+ },
+]
+
+export default function Checker() {
+ return (
+ <>
+ {checkList.map((item, i) => {
+ return
+ })}
+ >
+ )
+}
diff --git a/src/components/IPAddress.tsx b/src/components/IPAddress.tsx
new file mode 100644
index 0000000..c4d1cc7
--- /dev/null
+++ b/src/components/IPAddress.tsx
@@ -0,0 +1,10 @@
+type Props = {
+ address: string
+ version: number
+};
+
+export default function IPAddress({address, version}: Props) {
+ return (
+ IPv4 {address}
+ )
+}
\ No newline at end of file
diff --git a/src/components/Nav.tsx b/src/components/Nav.tsx
index 3f7ecb1..7415ddd 100644
--- a/src/components/Nav.tsx
+++ b/src/components/Nav.tsx
@@ -3,15 +3,15 @@ import Link from "next/link"
export default function Nav() {
return (
-
+
diff --git a/src/types/CheckItem.ts b/src/types/CheckItem.ts
new file mode 100644
index 0000000..40d84c8
--- /dev/null
+++ b/src/types/CheckItem.ts
@@ -0,0 +1,6 @@
+export interface CheckItemType {
+ url: string
+ content: (data: any) => {state: CheckItemIconState, text: string}
+}
+
+export type CheckItemIconState = "ok" | "loading" | "info" | "error"
diff --git a/src/types/MyIPResponse.ts b/src/types/MyIPResponse.ts
new file mode 100644
index 0000000..a7c31f4
--- /dev/null
+++ b/src/types/MyIPResponse.ts
@@ -0,0 +1,4 @@
+export default interface MyIPResponse {
+ address: string
+ version: number
+}
\ No newline at end of file