From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.Share/NetWork/TcpIP.cs |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Share/NetWork/TcpIP.cs b/HotelPms.Share/NetWork/TcpIP.cs
new file mode 100644
index 0000000..e5b1e0c
--- /dev/null
+++ b/HotelPms.Share/NetWork/TcpIP.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net.Sockets;
+using System.Net;
+
+namespace Common.NetWork
+{
+    public class TcpIP
+    {
+        /// <summary>
+        /// ip���A���g�p�|�[�g�̎擾
+        /// (1024�`65535)
+        /// </summary>
+        /// <param name="ip4"></param>
+        /// <returns>0:�擾���s</returns>
+        public static int GetFreePort(string ip4)
+        {
+            for (int i = 1024; i < 65535; i++)
+            {
+                if (IsFreePort(ip4, i)) { return i; }
+            }
+            return 0;
+        }
+
+        /// <summary>
+        /// �w�肵���|�[�g�͎g�p�”\���ǂ���
+        /// </summary>
+        /// <param name="ip4"></param>
+        /// <param name="port"></param>
+        /// <returns></returns>
+        public static bool IsFreePort(string ip4, int port)
+        {
+            using (TcpClient tc = new TcpClient())
+            {
+                try
+                {
+                    tc.Connect(ip4, port);
+                    return true;
+                }
+                catch (Exception e)
+                {
+                    System.Diagnostics.Debug.WriteLine(e.Message);
+                }
+            }
+            return false;
+        }
+
+        /// <summary> ����IP�̎擾
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetLocalIpv4()
+        {
+            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
+            List<string> IpCollection = new List<string>();
+            foreach (IPAddress ip in localIPs)
+            {
+                if (ip.AddressFamily == AddressFamily.InterNetwork) { IpCollection.Add(ip.ToString()); }
+            }
+            return IpCollection;
+        }
+
+        /// <summary> ����IP�̎擾
+        /// </summary>
+        /// <returns></returns>
+        public static string GetFirstLocalIpv4()
+        {
+            //192.168.�D��I�I�I
+            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
+            SortedList<string, string> IpCollection = new SortedList<string, string>();
+            foreach (IPAddress ip in localIPs)
+            {
+                if (ip.AddressFamily == AddressFamily.InterNetwork) { IpCollection.Add(string.Format("{0}-{1}", ip.ToString().StartsWith("192") ? "0" : "1", ip.ToString()), ip.ToString()); }
+            }
+            return IpCollection.Count == 0 ? string.Empty : IpCollection.Values[0];
+        }
+
+        /// <summary> ����IP�̎擾
+        /// </summary>
+        /// <returns></returns>
+        public static IPAddress GetFirstLocalIp4Address()
+        {
+            //192.168.�D��I�I�I
+            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
+            SortedList<string, IPAddress> IpCollection = new SortedList<string, IPAddress>();
+            foreach (IPAddress ip in localIPs)
+            {
+                if (ip.AddressFamily == AddressFamily.InterNetwork) { IpCollection.Add(string.Format("{0}-{1}", ip.ToString().StartsWith("192") ? "0" : "1", ip.ToString()), ip); }
+            }
+            return IpCollection.Count == 0 ? null : IpCollection.Values[0];
+        }
+    }
+}

--
Gitblit v1.10.0