Skip to content

Commit

Permalink
deep search
Browse files Browse the repository at this point in the history
  • Loading branch information
ircfspace committed Mar 6, 2024
1 parent ab8a008 commit 99d1de0
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 1 deletion.
136 changes: 136 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",
"axios": "^1.6.7",
"html-react-parser": "^5.1.8",
"next": "^14.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
28 changes: 28 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,34 @@ label {
float: right;
}

.myToast {
float: left;
}
.myToast .myToastConfirm {
float: left;
width: 100%;
margin: 10px 0 0 0;
}
.myToast .myToastConfirm button {
float: right;
padding: 5px 15px;
border-radius: 3px;
width: auto;
-webkit-transition: .2s;
transition: .2s;
}
.myToast .myToastConfirm button[data-act="restart"] {
float: right;
background: #4b4b4b;
}
.myToast .myToastConfirm button[data-act="cancel"] {
float: right;
margin-left: 7px;
}
.myToast .myToastConfirm button:hover {
background: #616060;
}

footer {
margin: 50px 0 20px 0;
padding: 10px 0;
Expand Down
60 changes: 59 additions & 1 deletion src/hooks/useIPScanner.ts → src/hooks/useIPScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { create } from "zustand";
import { persist } from "zustand/middleware";
import { randomizeElements } from "~/helpers/randomizeElements";
import axiosWithSNI from "./axiosWithSNI";
import {toast} from "react-hot-toast";

type ValidIP = {
ip: string;
Expand Down Expand Up @@ -106,7 +107,9 @@ export const useScannerStore = create<ScannerStore>()(
});
},
increaseTestNo: () => {
set((state) => ({ testNo: state.testNo + 1 }));
set((state) => ({
testNo: state.testNo + 1
}));
},
}),
{
Expand Down Expand Up @@ -168,6 +171,60 @@ export const useIPScanner = ({ allIps }: IPScannerProps) => {
https: [443, 8443, 2053, 2083, 2087, 2096],
};

async function reStart() {
toast.dismiss('limitation');
try {
const ips = state.ipRegex
? allIps.filter((el) => new RegExp(state.ipRegex).test(el))
: allIps;

dispatch({ scanState: "scanning" });
await testIPs(randomizeElements(ips));
setToIdle();
} catch (e) {
console.error(e);
}
}

async function showToast() {
toast(
(currentToast) => (
<span className="myToast">
In each search, only 150 IPs are evaluated. Do you want to search deeper?
<br />
<div className={"myToastConfirm"}>
<button
data-act="cancel"
onClick={() =>
toast.dismiss(currentToast?.id)
}
>
No
</button>
<button
data-act="restart"
onClick={() => {
reStart();
}}
>
Yes
</button>
</div>
</span>
),
{
id: "limitation",
duration: Infinity,
position:"bottom-center",
style: {
borderRadius: '10px',
background: '#333',
color: '#fff',
},
}
);
}

async function testIPs(ipList: string[]) {
let isSSL = false;
if (state.sniValue !== '' && ports.https.includes(state.portValue)) {
Expand Down Expand Up @@ -258,5 +315,6 @@ export const useIPScanner = ({ allIps }: IPScannerProps) => {
...state,
startScan,
stopScan,
showToast,
};
};
9 changes: 9 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const Home: NextPage = () => {
tryChar,
validIPs,
setSettings,
showToast,
} = useIPScanner({ allIps });

const isRunning = scanState !== "idle";
Expand All @@ -54,6 +55,14 @@ const Home: NextPage = () => {
setLoaded(true);
}, []);

useEffect(() => {
if ( testNo >= 150 ) {
showToast().then(r => {
//
});
}
}, [showToast, testNo]);

/*const router = useRouter();
useEffect(() => {
if (window.location.protocol === 'https:') {
Expand Down

0 comments on commit 99d1de0

Please sign in to comment.