Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/fixtures/resproxy/175.107.211.204.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ip": "175.107.211.204",
"last_seen": "2026-01-14",
"percent_days_seen": 50,
"service": "DataImpulse"
}
1 change: 1 addition & 0 deletions __tests__/fixtures/resproxy/8.8.8.8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
20 changes: 19 additions & 1 deletion __tests__/ipinfoWrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as dotenv from "dotenv";
import { AsnResponse, IPinfo } from "../src/common";
import { AsnResponse, IPinfo, Resproxy } from "../src/common";
import IPinfoWrapper from "../src/ipinfoWrapper";

let ipinfoWrapper: IPinfoWrapper;
Expand Down Expand Up @@ -195,6 +195,24 @@ describe("IPinfoWrapper", () => {
expect(data.bogon).toEqual(true);
});

test("lookupResproxy", async () => {
// test multiple times for cache.
for (let i = 0; i < 5; i++) {
const data: Resproxy = await ipinfoWrapper.lookupResproxy(
"175.107.211.204"
);
expect(data.ip).toEqual("175.107.211.204");
expect(data.last_seen).toEqual("2026-01-14");
expect(data.percent_days_seen).toEqual(50);
expect(data.service).toEqual("DataImpulse");
}
});

test("lookupResproxyEmpty", async () => {
const data: Resproxy = await ipinfoWrapper.lookupResproxy("8.8.8.8");
expect(data).toEqual({});
});

test("Error is thrown for invalid token", async () => {
const ipinfo = new IPinfoWrapper("invalid-token");
await expect(ipinfo.lookupIp("1.2.3.4")).rejects.toThrow();
Expand Down
16 changes: 16 additions & 0 deletions __tests__/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ module.exports = async function globalSetup() {
method: "POST",
path: "/tools/map",
response: path.resolve(__dirname, "./fixtures/tools/map.json")
},
{
method: "GET",
path: "/resproxy/175.107.211.204",
response: path.resolve(
__dirname,
"./fixtures/resproxy/175.107.211.204.json"
)
},
{
method: "GET",
path: "/resproxy/8.8.8.8",
response: path.resolve(
__dirname,
"./fixtures/resproxy/8.8.8.8.json"
)
}
]
};
Expand Down
3 changes: 0 additions & 3 deletions package-lock.json

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

8 changes: 8 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const HOST: string = "ipinfo.io";
export const HOST_LITE: string = "api.ipinfo.io/lite";
export const HOST_CORE: string = "api.ipinfo.io/lookup";
export const HOST_PLUS: string = "api.ipinfo.io/lookup";
export const HOST_RESPROXY: string = "ipinfo.io/resproxy";

// cache version
export const CACHE_VSN: string = "1";
Expand Down Expand Up @@ -244,6 +245,13 @@ export interface MapResponse {
reportUrl: string;
}

export interface Resproxy {
ip: string;
last_seen: string;
percent_days_seen: number;
service: string;
}

export interface BatchResponse {
[key: string]:
| IPinfo
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export {
Prefixes6,
AsnResponse,
MapResponse,
BatchResponse
BatchResponse,
Resproxy
} from "./common";

export default IPinfoWrapper;
21 changes: 21 additions & 0 deletions src/ipinfoWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
AsnResponse,
MapResponse,
BatchResponse,
Resproxy,
BATCH_MAX_SIZE,
BATCH_REQ_TIMEOUT_DEFAULT,
REQUEST_TIMEOUT_DEFAULT,
Expand Down Expand Up @@ -215,6 +216,26 @@ export default class IPinfoWrapper {
});
}

/**
* Lookup residential proxy information using the IP.
*
* @param ip IP address to check for residential proxy information.
* @return Response containing Resproxy data if the IP is a residential proxy.
*/
public async lookupResproxy(ip: string): Promise<Resproxy> {
const cacheKey = `resproxy:${ip}`;
const data = await this.cache.get(IPinfoWrapper.cacheKey(cacheKey));
if (data) {
return data;
}

return this.fetchApi(`resproxy/${ip}`).then(async (response) => {
const resproxy = (await response.json()) as Resproxy;
this.cache.set(IPinfoWrapper.cacheKey(cacheKey), resproxy);
return resproxy;
});
}

/**
* Get a mapping of a list of IPs on a world map.
*
Expand Down