Skip to content

Commit 6b02b38

Browse files
authored
Merge pull request #2 from acarteas/issue-1
In response to issue #1, the program now prompts the user for the IP …
2 parents db4f01b + db50b2d commit 6b02b38

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Directory2Rss.ConsoleApp/Program.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Directory2Rss.Library;
22
using Swan;
33
using System;
4+
using System.Collections.Generic;
45
using System.IO;
56
using System.Threading.Tasks;
67

@@ -24,8 +25,29 @@ static void setOption(ref string input, string option)
2425
static async Task Main(string[] args)
2526
{
2627
PodcastConfig config = new PodcastConfig();
28+
List<string> ipAddressList = PodcastConfig.GetLocalIpAddresses();
29+
string response = "";
30+
int option = -1;
31+
32+
Console.WriteLine("Select IP address to bind: ", config.DirectoryToServe);
33+
for(int i = 0; i < ipAddressList.Count; i++)
34+
{
35+
Console.WriteLine("{0}: {1}", i, ipAddressList[i]);
36+
}
37+
response = Console.ReadLine();
38+
Int32.TryParse(response, out option);
39+
if(option < ipAddressList.Count)
40+
{
41+
config.IPAddress = ipAddressList[option];
42+
}
43+
else
44+
{
45+
Console.WriteLine("Invalid option, exiting...");
46+
return;
47+
}
48+
2749
Console.WriteLine("Enter directory to serve [{0}]: ", config.DirectoryToServe);
28-
string response = Console.ReadLine();
50+
response = Console.ReadLine();
2951
if(response.Length > 0)
3052
{
3153
if(Directory.Exists(response))

src/Directory2Rss.Library/PodcastConfig.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ public PodcastConfig()
2929
PodcastCategory = "Music";
3030
}
3131

32+
public static List<string> GetLocalIpAddresses()
33+
{
34+
List<string> result = new List<string>();
35+
var host = Dns.GetHostEntry(Dns.GetHostName());
36+
foreach (var ip in host.AddressList)
37+
{
38+
if (ip.AddressFamily == AddressFamily.InterNetwork)
39+
{
40+
result.Add(ip.ToString());
41+
}
42+
}
43+
return result;
44+
}
45+
3246
public static string GetLocalIPAddress()
3347
{
3448
var host = Dns.GetHostEntry(Dns.GetHostName());

0 commit comments

Comments
 (0)