init commit

This commit is contained in:
Blake Ridgway 2025-06-10 21:13:00 -05:00
commit 54c5ae2945
34 changed files with 468 additions and 0 deletions

13
.idea/.idea.url_gen/.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.url_gen.iml
/modules.xml
/projectSettingsUpdater.xml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

4
.idea/.idea.url_gen/.idea/encodings.xml generated Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

77
Program.cs Normal file
View file

@ -0,0 +1,77 @@
using System;
using System.Security.Cryptography;
using System.Text;
while (true)
{
Console.WriteLine("Select a server type:");
Console.WriteLine("1. PostgreSQL (psql)");
Console.WriteLine("2. Redis (redis)");
Console.WriteLine("3. RabbitMQ (rabbitmq)");
Console.WriteLine("4. Sandbox Web Server (sandbox)");
Console.WriteLine("5. Staging Web Server (staging)");
Console.WriteLine("q. Exit");
Console.WriteLine();
Console.Write(
"Enter a number (1-5) to select a server type, or 'q' to quit: "
);
string choice = Console.ReadLine();
if (choice?.ToLower() == "q")
{
break;
}
string prefix = choice switch
{
"1" => "psql",
"2" => "redis",
"3" => "rabbitmq",
"4" => "sandbox",
"5" => "staging",
_ => null
};
if (prefix == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Invalid choice. Please try again: ");
Console.ResetColor();
Console.WriteLine();
continue;
}
string randomUrl = GenerateRandomUrl(prefix);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Generated URL: {randomUrl}");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Generate another URL? (y/n)");
string another = Console.ReadLine();
if (another?.ToLower() != "y")
{
break;
}
Console.WriteLine();
}
static string GenerateRandomUrl(string prefix, int length = 12)
{
const string alphabet = "abcdefghijklmnopqrstuvqxyz123456789";
var resultBuilder = new StringBuilder(length);
byte[] randomBytes = new byte[length];
RandomNumberGenerator.Fill(randomBytes);
foreach (byte b in randomBytes)
{
resultBuilder.Append(alphabet[b % alphabet.Length]);
}
string randomString = resultBuilder.ToString();
return $"{prefix}-{randomString}.rideaware.org";
}

76
README.md Normal file
View file

@ -0,0 +1,76 @@
# Random URL Generator
A simple, cross-platform command-line utility for generating cryptographically secure, random URLs. This project is a C# port of an original Python script, designed to provide unique, non-guessable hostnames for development and testing environments.
## Features
- **Interactive Menu**: Simple menu to select the desired server type.
- **Secure by Default**: Uses `System.Security.Cryptography.RandomNumberGenerator` for cryptographically strong randomness, equivalent to Python's `secrets` module.
- **Customizable Prefixes**: Easily generates URLs for different services (PostgreSQL, Redis, RabbitMQ, etc.).
- **Modern C#**: Written using modern C# features like top-level statements and switch expressions for clean, concise code.
- **Cross-Platform**: Runs anywhere the .NET SDK is installed (Windows, macOS, Linux).
## Purpose
In development and cloud environments, there is often a need to create temporary resources with unique hostnames. This tool solves that problem by generating random, hard-to-guess URLs, which helps:
1. **Prevent Naming Collisions**: The random string ensures each generated URL is unique.
2. **Enhance Security through Obscurity**: While not a replacement for proper authentication, a non-guessable hostname makes it harder for unauthorized users to discover or access temporary services.
## Prerequisites
To run this project, you will need the **.NET 6 SDK** or later installed on your system.
- [Download the .NET SDK](https://dotnet.microsoft.com/download)
## How to Run
1. **Clone or Download the Code**
Clone this repository to your local machine or simply download the `Program.cs` file.
```bash
git clone https://github.com/rideaware/url_gen.git
cd url_gen
```
2. **Run from the Command Line**
Navigate to the project's root directory in your terminal and use the `dotnet run` command. The .NET SDK will automatically compile and execute the application.
```bash
dotnet run
```
3. **Follow the Prompts**
The application will present you with a menu. Enter the number corresponding to your choice and press Enter.
### Example Session
```
Select a server type:
1. PostgreSQL (psql)
2. Redis (redis)
3. RabbitMQ (rabbitmq)
4. Sandbox Web Server (sandbox)
5. Staging Web Server (staging)
Enter a number (1-5) to select a server type, or 'q' to quit: 1
Generated URL: psql-4t9wz1qj.rideaware.org
Generate another URL? (y/n): y
Select a server type:
1. PostgreSQL (psql)
2. Redis (redis)
3. RabbitMQ (rabbitmq)
4. Sandbox Web Server (sandbox)
5. Staging Web Server (staging)
Enter a number (1-5) to select a server type, or 'q' to quit: 4
Generated URL: sandbox-k8m3v7b2.rideaware.org
Generate another URL? (y/n): n
```
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.

BIN
bin/Debug/net8.0/url_gen Executable file

Binary file not shown.

View file

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"url_gen/1.0.0": {
"runtime": {
"url_gen.dll": {}
}
}
}
},
"libraries": {
"url_gen/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View file

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

BIN
obj/Debug/net8.0/apphost Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("url_gen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("url_gen")]
[assembly: System.Reflection.AssemblyTitleAttribute("url_gen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -0,0 +1 @@
ee24cc1783beb9403012c2aca99ef562f4dea2fc3f355d9f7b937558dbcefd77

View file

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = url_gen
build_property.ProjectDir = /home/blake/RiderProjects/url_gen/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View file

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View file

@ -0,0 +1 @@
2d4611aa53284e486385d76846ea98b77390d71b23c31d887aee839a555fe341

View file

@ -0,0 +1,14 @@
/home/blake/RiderProjects/url_gen/bin/Debug/net8.0/url_gen
/home/blake/RiderProjects/url_gen/bin/Debug/net8.0/url_gen.deps.json
/home/blake/RiderProjects/url_gen/bin/Debug/net8.0/url_gen.runtimeconfig.json
/home/blake/RiderProjects/url_gen/bin/Debug/net8.0/url_gen.dll
/home/blake/RiderProjects/url_gen/bin/Debug/net8.0/url_gen.pdb
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.GeneratedMSBuildEditorConfig.editorconfig
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.AssemblyInfoInputs.cache
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.AssemblyInfo.cs
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.csproj.CoreCompileInputs.cache
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.dll
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/refint/url_gen.dll
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.pdb
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/url_gen.genruntimeconfig.cache
/home/blake/RiderProjects/url_gen/obj/Debug/net8.0/ref/url_gen.dll

Binary file not shown.

View file

@ -0,0 +1 @@
491da53b44b4b615669dbde737345b0b710fb40255e11aa89ff78637827d8579

Binary file not shown.

71
obj/project.assets.json Normal file
View file

@ -0,0 +1,71 @@
{
"version": 3,
"targets": {
"net8.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
},
"packageFolders": {
"/home/blake/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/blake/RiderProjects/url_gen/url_gen.csproj",
"projectName": "url_gen",
"projectPath": "/home/blake/RiderProjects/url_gen/url_gen.csproj",
"packagesPath": "/home/blake/.nuget/packages/",
"outputPath": "/home/blake/RiderProjects/url_gen/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/blake/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/home/blake/.dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json"
}
}
}
}

8
obj/project.nuget.cache Normal file
View file

@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "HU0CEgohj/I=",
"success": true,
"projectFilePath": "/home/blake/RiderProjects/url_gen/url_gen.csproj",
"expectedPackageFiles": [],
"logs": []
}

View file

@ -0,0 +1 @@
"restore":{"projectUniqueName":"/home/blake/RiderProjects/url_gen/url_gen.csproj","projectName":"url_gen","projectPath":"/home/blake/RiderProjects/url_gen/url_gen.csproj","outputPath":"/home/blake/RiderProjects/url_gen/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]},"restoreAuditProperties":{"enableAudit":"true","auditLevel":"low","auditMode":"direct"}}"frameworks":{"net8.0":{"targetAlias":"net8.0","imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/home/blake/.dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json"}}

View file

@ -0,0 +1 @@
17496078996109873

View file

@ -0,0 +1 @@
17496078996109873

View file

@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"/home/blake/RiderProjects/url_gen/url_gen.csproj": {}
},
"projects": {
"/home/blake/RiderProjects/url_gen/url_gen.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/blake/RiderProjects/url_gen/url_gen.csproj",
"projectName": "url_gen",
"projectPath": "/home/blake/RiderProjects/url_gen/url_gen.csproj",
"packagesPath": "/home/blake/.nuget/packages/",
"outputPath": "/home/blake/RiderProjects/url_gen/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/blake/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/home/blake/.dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/blake/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/blake/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/blake/.nuget/packages/" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

10
url_gen.csproj Normal file
View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

16
url_gen.sln Normal file
View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "url_gen", "url_gen.csproj", "{A01FD250-6C80-4037-9C44-A7820FB61475}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A01FD250-6C80-4037-9C44-A7820FB61475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A01FD250-6C80-4037-9C44-A7820FB61475}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A01FD250-6C80-4037-9C44-A7820FB61475}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A01FD250-6C80-4037-9C44-A7820FB61475}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal