fixed getting ip

This commit is contained in:
”minicx” 2022-12-02 14:44:14 +03:00
parent 9a50b30d54
commit 6541e453c0
4 changed files with 31 additions and 9 deletions

View File

@ -132,7 +132,8 @@ const addAccounts: ()=>Promise<void>=async ()=>{
const farm: ()=>Promise<void>=async ()=>{
const proccesGroup=async (workers_group:AccountInterface[],ports: number[])=>{
const container=await startNewTorDocker(ports[0],ports[1],ports[2]);
await getIP(ports[0]);
console.log(0)
console.log(await getIP(ports[0]));
console.log(1)
for (const worker of workers_group){
logger.debug(`Current worker:${worker.phoneNumber}\nBalance:${worker.balance}`);
@ -180,8 +181,8 @@ const farm: ()=>Promise<void>=async ()=>{
name: 'menu',
message: 'Choose action',
choices: [
{ title: 'Add accounts', description: 'Adds accounts', value: 'addAccounts' },
((await db.getUsers()).length>0) ? { title: 'Start',description: 'Starting farm', value: 'start' } : { title: 'Start',description: 'Add accounts first...', value: 'start' ,disabled: true},
{ title: 'Add accounts', description: 'Adds accounts', value: 'addAccounts' },
{ title: 'Check balances', value: 'checkBalances', disabled: true },
{ title: 'Withdraw', value: 'withdraw', disabled: true },
{ title: 'Exit',description: 'You realy dont know what it mean?'}

View File

@ -8,6 +8,7 @@
"fingerprint-generator": "^2.1.5",
"node-json-db": "^2.1.3",
"node-tor-control": "^0.0.2",
"progress": "^2.0.3",
"prompts": "^2.4.2",
"socks5-https-client": "^1.2.1",
"telegram": "^2.14.7",
@ -21,6 +22,7 @@
"devDependencies": {
"@types/dockerode": "^3.3.14",
"@types/node": "^18.11.9",
"@types/progress": "^2.0.5",
"@types/prompts": "^2.4.1"
},
"scripts": {

View File

@ -8,8 +8,9 @@ import { sleep } from "telegram/Helpers";
import { AccountInterface } from "./interfaces/databaseInterface";
import * as telegram from 'telegram';
import axios from "axios";
import ProgessBar from "progress"
export const getIP=async function (proxyPort: number): Promise<string> {
export const getIP=async function (proxyPort: number): Promise<string | null> {
// const res=await shttps.get({
// url: 'icanhazip.com',
// agentOptions: {
@ -17,12 +18,15 @@ export const getIP=async function (proxyPort: number): Promise<string> {
// }
// })
// console.log(res.body)
const {data}=await axios.get('https://api.ipify.org',{
const {data}=await axios.get('http://api.ipify.org',{
proxy:{
host:'127.0.0.1',
port:proxyPort
}
});
if (data.trim()==""){
return null
}
return data
}
@ -87,29 +91,37 @@ export const startNewTorDocker=async function(proxyPort: number,socksPort: numbe
}
}
logger.debug(`Creating container with this ports ${proxyPort} ${socksPort} ${controlPort}`);
const container=await docker.createContainer(options);
await container.start();
const start_time=(new Date());
const progressBar=new ProgessBar(`Timeout [:bar] :current/:total sec`,{
total:timeout/2,
width: 50,
complete: '❌',
incomplete: '✔️',
clear: true,
});
while ((await container.inspect())!.State.Health!.Status!='healthy'){
const state=(await container.inspect())!.State.Health!.Status
const current_time=(new Date());
if ((+current_time-+start_time)/1000>=timeout){
await container.kill();
progressBar.terminate();
throw new Error(`Docker ${container.id} is broken`);
}
if (state=='unhealthy'){
await container.kill();
progressBar.terminate();
logger.warn(`Docker ${container.id} is unhealthy.Recreating...`);
return await startNewTorDocker(proxyPort,socksPort,controlPort,timeout);
}
progressBar.tick();
await sleep(2000);
}
return container
progressBar.terminate();
return container;
}

View File

@ -57,6 +57,13 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.10.tgz#4c64759f3c2343b7e6c4b9caf761c7a3a05cee34"
integrity sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==
"@types/progress@^2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@types/progress/-/progress-2.0.5.tgz#6e0febf3a82cc0ffdc1cebb4e56d6949fd108775"
integrity sha512-ZYYVc/kSMkhH9W/4dNK/sLNra3cnkfT2nJyOAIDY+C2u6w72wa0s1aXAezVtbTsnN8HID1uhXCrLwDE2ZXpplg==
dependencies:
"@types/node" "*"
"@types/prompts@^2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.4.1.tgz#d47adcb608a0afcd48121ff7c75244694a3a04c5"