npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

khmer-ip-generator

v2.0.11

Published

Generate random Cambodian (Khmer) IP addresses from known IP ranges

Readme

Khmer IP Generator

Khmer IP Generator

A lightweight, dependency-free JavaScript library for generating random Cambodian (Khmer) IP addresses from verified IP ranges. Ideal for testing geo-based features, localization systems, analytics platforms, and security applications.

npm version License GitHub Issues Build Status


🎥 Video Demo

Live demo: ip-khmer-generator.rithytep.online

Version: 2.0.11 Maintainer: Rithy Tep (YouTube | Facebook) Last Updated: May 2025

Features

  • Lightweight: No runtime dependencies, minimal bundle size.
  • Accurate: Uses verified Cambodian IP ranges from APNIC and other registries.
  • Versatile: Supports Node.js, React, Vue, Angular, Svelte, Next.js, Nuxt.js, and more.
  • TypeScript Ready: Includes built-in type definitions.

Installation

Install via npm:

npm install khmer-ip-generator

Or with Yarn:

yarn add khmer-ip-generator

Quick Start

Generate a Single IP

import { generateKhmerIp } from 'khmer-ip-generator';

const ip = generateKhmerIp();
console.log(ip); // Example: "103.111.197.24"

Generate Multiple IPs

import { generateMultipleKhmerIps } from 'khmer-ip-generator';

const ips = generateMultipleKhmerIps(5); // 5 random IPs
const uniqueIps = generateMultipleKhmerIps(5, true); // 5 unique IPs
console.log(ips); // Example: ["34.98.224.91", "154.217.71.43", ...]

API Reference

| Function | Description | Parameters | Returns | | ------------------------------------------ | ------------------------------------------------ | ----------------------------------- | ---------- | | generateKhmerIp() | Generates a random Cambodian IP address. | None | string | | generateMultipleKhmerIps(count, unique?) | Generates multiple random IPs. | count: number, unique?: boolean | string[] | | isKhmerIp(ip) | Validates if an IP belongs to a Cambodian range. | ip: string | boolean | | getKhmerIpRangesCount() | Returns the count of Cambodian IP ranges. | None | number |

Example:

import { isKhmerIp } from 'khmer-ip-generator';

console.log(isKhmerIp("103.111.197.24")); // true or false

Framework Integrations

Node.js (CommonJS)

const { generateKhmerIp } = require('khmer-ip-generator');
console.log(generateKhmerIp()); // "103.206.68.78"

React (Hooks)

import React, { useState } from 'react';
import { generateKhmerIp } from 'khmer-ip-generator';

function IpGenerator() {
  const [ip, setIp] = useState(generateKhmerIp());

  return (
    <div>
      <button onClick={() => setIp(generateKhmerIp())}>New IP</button>
      <p>IP: {ip}</p>
    </div>
  );
}
export default IpGenerator;

Vue 3 (Composition API)

<template>
  <div>
    <button @click="generateIp">Generate IP</button>
    <p>IP: {{ ip }}</p>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { generateKhmerIp } from 'khmer-ip-generator';

const ip = ref(generateKhmerIp());
const generateIp = () => {
  ip.value = generateKhmerIp();
};
</script>

Angular (Service)

import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { generateKhmerIp } from 'khmer-ip-generator';

@Injectable({ providedIn: 'root' })
export class KhmerIpService {
  generateIp(): Observable<string> {
    return of(generateKhmerIp());
  }
}

Svelte

<script>
  import { generateKhmerIp } from 'khmer-ip-generator';
  let ip = generateKhmerIp();

  function generateIp() {
    ip = generateKhmerIp();
  }
</script>

<div>
  <button on:click={generateIp}>Generate IP</button>
  <p>IP: {ip}</p>
</div>

Next.js (API Route)

// pages/api/ip.js
import { generateKhmerIp } from 'khmer-ip-generator';

export default function handler(req, res) {
  if (req.method === 'GET') {
    res.status(200).json({ ip: generateKhmerIp() });
  } else {
    res.status(405).json({ error: 'Method Not Allowed' });
  }
}

Use Cases

  • Quality Assurance: Test geographic restrictions, location-based authentication, and regional content delivery.
  • Analytics: Simulate regional traffic, analyze geographic data, or conduct market research.
  • Security: Simulate IP whitelists, test access controls, or assess network security.
  • Localization: Validate Cambodia-specific features or personalize regional content.

Technical Details

Data Source

IP ranges are sourced from APNIC and other regional internet registries, ensuring accuracy and compliance.

Performance

  • Zero Dependencies: Minimal bundle size.
  • Fast Generation: Optimized random IP generation.
  • Memory Efficient: Lazy-loaded data structures.
  • Thread-Safe: Suitable for multi-threaded environments.

Compatibility

| Framework/Environment | Support | TypeScript | SSR | | --------------------- | ------- | ---------- | --- | | Node.js | ✅ | ✅ | ✅ | | React | ✅ | ✅ | ✅ | | Vue.js | ✅ | ✅ | ✅ | | Angular | ✅ | ✅ | ✅ | | Svelte | ✅ | ✅ | ✅ | | Next.js | ✅ | ✅ | ✅ | | Nuxt.js | ✅ | ✅ | ✅ |


FAQs

Why use Khmer IP Generator?

It provides accurate Cambodian IP addresses for testing geo-specific features without relying on external APIs, ensuring privacy and performance.

How are IP ranges verified?

Ranges are sourced from APNIC and cross-checked with other registries for accuracy.

Can I use this in production?

This library is designed for testing and development. For production, ensure compliance with local regulations.

What if I need unique IPs?

Use generateMultipleKhmerIps(count, true) to ensure unique IP addresses.


Troubleshooting

  • Invalid IP Generated?

    • Ensure you're using the latest version (2.0.0).
    • Verify the IP with isKhmerIp(ip) to confirm it’s in a Cambodian range.
  • Performance Issues?

    • Generating large numbers of unique IPs (e.g., >10,000) may be slower due to uniqueness checks.
  • Framework Errors?

    • Check for correct imports (ES Modules vs. CommonJS).
    • Ensure TypeScript is configured if using types.

File issues at GitHub Issues.


Contributing

We welcome contributions! Follow these steps:

  1. Fork the repository: github.com/rithytep/generateKhmerIp
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Write tests for new functionality.
  4. Follow the existing code style (use ESLint/Prettier).
  5. Update documentation for API changes.
  6. Submit a pull request with a clear description.

See CONTRIBUTING.md for details.


License

MIT License - Free for personal and commercial use.


Support

For bugs, feature requests, or questions, visit our GitHub Issues page or contact the maintainer:


Version: 2.0.11 Repository: github.com/rithytep/generateKhmerIp