fixed getting ip
This commit is contained in:
parent
9a50b30d54
commit
6541e453c0
5
index.ts
5
index.ts
|
@ -132,7 +132,8 @@ const addAccounts: ()=>Promise<void>=async ()=>{
|
||||||
const farm: ()=>Promise<void>=async ()=>{
|
const farm: ()=>Promise<void>=async ()=>{
|
||||||
const proccesGroup=async (workers_group:AccountInterface[],ports: number[])=>{
|
const proccesGroup=async (workers_group:AccountInterface[],ports: number[])=>{
|
||||||
const container=await startNewTorDocker(ports[0],ports[1],ports[2]);
|
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)
|
console.log(1)
|
||||||
for (const worker of workers_group){
|
for (const worker of workers_group){
|
||||||
logger.debug(`Current worker:${worker.phoneNumber}\nBalance:${worker.balance}`);
|
logger.debug(`Current worker:${worker.phoneNumber}\nBalance:${worker.balance}`);
|
||||||
|
@ -180,8 +181,8 @@ const farm: ()=>Promise<void>=async ()=>{
|
||||||
name: 'menu',
|
name: 'menu',
|
||||||
message: 'Choose action',
|
message: 'Choose action',
|
||||||
choices: [
|
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},
|
((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: 'Check balances', value: 'checkBalances', disabled: true },
|
||||||
{ title: 'Withdraw', value: 'withdraw', disabled: true },
|
{ title: 'Withdraw', value: 'withdraw', disabled: true },
|
||||||
{ title: 'Exit',description: 'You realy dont know what it mean?'}
|
{ title: 'Exit',description: 'You realy dont know what it mean?'}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"fingerprint-generator": "^2.1.5",
|
"fingerprint-generator": "^2.1.5",
|
||||||
"node-json-db": "^2.1.3",
|
"node-json-db": "^2.1.3",
|
||||||
"node-tor-control": "^0.0.2",
|
"node-tor-control": "^0.0.2",
|
||||||
|
"progress": "^2.0.3",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"socks5-https-client": "^1.2.1",
|
"socks5-https-client": "^1.2.1",
|
||||||
"telegram": "^2.14.7",
|
"telegram": "^2.14.7",
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/dockerode": "^3.3.14",
|
"@types/dockerode": "^3.3.14",
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^18.11.9",
|
||||||
|
"@types/progress": "^2.0.5",
|
||||||
"@types/prompts": "^2.4.1"
|
"@types/prompts": "^2.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
26
utils.ts
26
utils.ts
|
@ -8,8 +8,9 @@ import { sleep } from "telegram/Helpers";
|
||||||
import { AccountInterface } from "./interfaces/databaseInterface";
|
import { AccountInterface } from "./interfaces/databaseInterface";
|
||||||
import * as telegram from 'telegram';
|
import * as telegram from 'telegram';
|
||||||
import axios from "axios";
|
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({
|
// const res=await shttps.get({
|
||||||
// url: 'icanhazip.com',
|
// url: 'icanhazip.com',
|
||||||
// agentOptions: {
|
// agentOptions: {
|
||||||
|
@ -17,12 +18,15 @@ export const getIP=async function (proxyPort: number): Promise<string> {
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// console.log(res.body)
|
// console.log(res.body)
|
||||||
const {data}=await axios.get('https://api.ipify.org',{
|
const {data}=await axios.get('http://api.ipify.org',{
|
||||||
proxy:{
|
proxy:{
|
||||||
host:'127.0.0.1',
|
host:'127.0.0.1',
|
||||||
port:proxyPort
|
port:proxyPort
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (data.trim()==""){
|
||||||
|
return null
|
||||||
|
}
|
||||||
return data
|
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);
|
const container=await docker.createContainer(options);
|
||||||
|
|
||||||
await container.start();
|
await container.start();
|
||||||
const start_time=(new Date());
|
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'){
|
while ((await container.inspect())!.State.Health!.Status!='healthy'){
|
||||||
const state=(await container.inspect())!.State.Health!.Status
|
const state=(await container.inspect())!.State.Health!.Status
|
||||||
const current_time=(new Date());
|
const current_time=(new Date());
|
||||||
if ((+current_time-+start_time)/1000>=timeout){
|
if ((+current_time-+start_time)/1000>=timeout){
|
||||||
await container.kill();
|
await container.kill();
|
||||||
|
progressBar.terminate();
|
||||||
throw new Error(`Docker ${container.id} is broken`);
|
throw new Error(`Docker ${container.id} is broken`);
|
||||||
}
|
}
|
||||||
if (state=='unhealthy'){
|
if (state=='unhealthy'){
|
||||||
await container.kill();
|
await container.kill();
|
||||||
|
progressBar.terminate();
|
||||||
logger.warn(`Docker ${container.id} is unhealthy.Recreating...`);
|
logger.warn(`Docker ${container.id} is unhealthy.Recreating...`);
|
||||||
return await startNewTorDocker(proxyPort,socksPort,controlPort,timeout);
|
return await startNewTorDocker(proxyPort,socksPort,controlPort,timeout);
|
||||||
}
|
}
|
||||||
|
progressBar.tick();
|
||||||
await sleep(2000);
|
await sleep(2000);
|
||||||
}
|
}
|
||||||
|
progressBar.terminate();
|
||||||
|
return container;
|
||||||
return container
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,13 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.10.tgz#4c64759f3c2343b7e6c4b9caf761c7a3a05cee34"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.10.tgz#4c64759f3c2343b7e6c4b9caf761c7a3a05cee34"
|
||||||
integrity sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==
|
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":
|
"@types/prompts@^2.4.1":
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.4.1.tgz#d47adcb608a0afcd48121ff7c75244694a3a04c5"
|
resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.4.1.tgz#d47adcb608a0afcd48121ff7c75244694a3a04c5"
|
||||||
|
|
Loading…
Reference in a new issue