Comments (9)
Hey @johngagefaulkner, Many congratulations for the newborn ❤️
The idea is to not depend from a hosted file but that everyone can edit their own.
The StunServers.json
can be in the same path of the portable app, generated itself when the app start if it doesn't exist, loaded in to dataGridView if exist ;) For me the json
file is ok.
Can you also add a new tab in the app to save, delete the StunServer lists from the json using dataGridView?
You can try to implement this and send me a PR, that would be great.
Many thanks and have a nice weekend.
from p2p.
Not sure if anyone has made any progress on this but I converted the long list of URLs and Ports for the Stun Servers to a .JSON
file: StunServers.json.txt
Note: Don't forget to remove the
.txt
extension from the end of the file name before using it with the code below.
I'm working on converting all the code over to .NET 6
for a personal project but I also wanted/needed to test my code on the existing/working .NET Framework v4.8
codebase so I've included the model(s) for both. Each class also contains methods to import the .JSON
file from either a local file, a URL, or using a JSON string that has otherwise already been imported.
- Here's the model class for
.NET 6
:
using System.IO;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
public class StunServer
{
public string? Url { get; set; }
public int Port { get; set; }
/// <summary>
/// Loads list of Stun Servers from a local file path.
/// </summary>
/// <param name="filePath">Full path to the local Stun Server list (.JSON). Example: C:\Users\Administrator\Downloads\StunServers.json</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[]? GetStunServersFromFile(string filePath)
{
string _json = File.ReadAllText(filePath);
return JsonSerializer.Deserialize<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from an HTTP/HTTPS URL.
/// </summary>
/// <param name="fileUrl">Full URL to the Stun Server list (.JSON). Example: "https://raw.github.com/username/repo/files/StunServers.json"</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static async Task<StunServer[]?> GetStunServersFromUrl(string fileUrl)
{
string _json;
using (HttpClient _client = new())
{
_json = await _client.GetStringAsync(fileUrl);
}
return JsonSerializer.Deserialize<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from a pre-populated JSON string.
/// </summary>
/// <param name="json">A string, in JSON format, containing an array of Stun Server objects.</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[]? GetStunServersFromJson(string json)
{
return JsonSerializer.Deserialize<StunServer[]>(json);
}
}
- And the
.NET Framework v4.8
model class:
// .NET Framework v4.8
// Requires Newtonsoft.Json
using System.IO;
using System.Net;
using Newtonsoft.Json;
public class StunServer
{
public string Url { get; set; }
public int Port { get; set; }
/// <summary>
/// Loads list of Stun Servers from a local file path.
/// </summary>
/// <param name="filePath">Full path to the local Stun Server list (.JSON). Example: C:\Users\Administrator\Downloads\StunServers.json</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromFile(string filePath)
{
string _json = System.IO.File.ReadAllText(filePath);
return JsonConvert.DeserializeObject<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from an HTTP/HTTPS URL.
/// </summary>
/// <param name="fileUrl">Full URL to the Stun Server list (.JSON). Example: "https://raw.github.com/username/repo/files/StunServers.json"</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromUrl(string fileUrl)
{
string _json;
using (System.Net.WebClient wc = new System.Net.WebClient())
{
_json = wc.DownloadString(fileUrl);
}
return JsonConvert.DeserializeObject<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from a pre-populated JSON string.
/// </summary>
/// <param name="json">A string, in JSON format, containing an array of Stun Server objects.</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromJson(string json)
{
return JsonConvert.DeserializeObject<StunServer[]>(json);
}
}
Finally if, for whatever reason, you still want/need to generate a list of Tuples from the StunServer object array:
List<Tuple<string, int>> stunServers = new List<Tuple<string, int>>();
foreach (var _server in p2p.Models.StunServer.GetStunServersFromFile(@"C:\Dev\StunServers.json"))
{
stunServers.Add(new Tuple<string, int>(_server.Url, _server.Port));
}
from p2p.
Hi @mubix, thank you for this news.
Sure, I deleted all Hardcoded Stun Servers, only leaving as default
[{
"Server": "stun.l.google.com",
"Port": 19302
}]
Now you can set your own List of Stun Servers that will be saved in the same dir where the app was run as StunServers.json
.
You can see the lists of Stun Servers by clicking on Stun tab, also add new, save - delete your own.
Special Thanks to @Darthagnon (this task) and @johngagefaulkner for the StunServer.cs
Thank you and enjoy!
from p2p.
Hello @Darthagnon, thanks, that's a great idea.
from p2p.
Hey @johngagefaulkner,
Thank you so much for sharing your great work, let's see if there are any other proposals for this implementation.
from p2p.
Hey @johngagefaulkner,
Thank you so much for sharing your great work, let's see if there are any other proposals for this implementation.
Fair warning, I haven't been to sleep in almost 2 days now (we have a newborn) so please forgive me if this suggestion doesn't make any sense, BUT...
I don't think it'd be a bad idea for you, as the author of the project, to be in control of the list of available Stun Servers and their ports. You could always host it on this GitHub repo, hard-code the URL into the project, and download it (for local cache) on each user's machine. I'm not all too familiar with the process but I'd imagine not all 290+ in the list are needed so you could have a shorter list containing only the ones you deem necessary which would reduce bandwidth costs for GitHub. If the user isn't able to use any of what's available in that file, they can click a button to "try additional servers" which would pull the full list. Once one, or both, of the lists are cached locally, you wouldn't need to check for an updated list again unless there were issues using whatever each user had locally.
Let me know if you're interested and need any help.
from p2p.
There are a couple servers like stunserver.org
that are no longer valid STUN servers as the domains have been released. Currently there is malware hosted on that particular one. Can we limit the server list to "known good"? Pretty easy to compile without them but just trying to look out for other users.
from p2p.
No thanks needed! I'm sorry I haven't responded, kids & career are working in tandem to hold my free time hostage!
from p2p.
@johngagefaulkner Deserved, you did a great job for the StunServer.cs
;)
No problem, I Understand you, I waited a while and in the end, having no news, I made the commit.
I wish you all the best and thank you for your valuable contribution.
from p2p.
Related Issues (20)
- Trojan Horse detected HOT 9
- Idea about cryptography HOT 1
- join the repository
- Can we have the source of the server please ? HOT 1
- Reported as virus
- Capture UAC messages
- virus win32 detect from avast HOT 1
- Grey Screen During Remote HOT 2
- Could not find a working STUN server HOT 1
- Trojan HOT 1
- Connect clients using WAN HOT 7
- App is crashing if endpoint is without port number
- Can´t connect with stun server. HOT 2
- Error when Build HOT 2
- test result HOT 1
- HELLO CAN YOU SHARE THE BUILD EXE THANKS HOT 1
- Two nodes cannot connect to each other and are not on the same LAN. Why?
- How to build self-hosted P2P intermediate server like Stun(http://stun.l.goolg.com) ? HOT 1
- Ctrl+Alt+Del
- Stun server doesnt work / ipv6 ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p2p.