C#操作靜態路由表(增、刪、改、查、遍歷)

C#操作靜態路由表,通過Windows原生API進行操作(效率比通過CMD操作的高很多),支持增、刪、改、查、遍歷使用的是Iphlpapi.dll庫,這個庫里面還有很多很好用的API,有興趣的童鞋自行研究吧,這里只用了路由表相關的API這個,那個,好像沒啥好說了,接下來直接看代碼吧等等,差點忘了,如果有童鞋需要需要Demo,那么請下載“C#通過DotRas實現完美控制VPN和PPPoE(ADSL)”這篇博文里的Demo(里面也使用了路由表操作)好了,下面看代碼using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Runtime.InteropServices;namespace RBTI.Toolbox.RasConnect.Network
{static class RouteTableManager{public enum MIB_IPFORWARD_TYPE : uint{/// <summary>/// Some other type not specified in RFC 1354./// </summary>MIB_IPROUTE_TYPE_OTHER = 1,/// <summary>/// An invalid route. This value can result from a route added by an ICMP redirect./// </summary>MIB_IPROUTE_TYPE_INVALID = 2,/// <summary>/// A local route where the next hop is the final destination (a local interface)./// </summary>MIB_IPROUTE_TYPE_DIRECT = 3,/// <summary>/// The remote route where the next hop is not the final destination (a remote destination)./// </summary>MIB_IPROUTE_TYPE_INDIRECT = 4}public enum MIB_IPPROTO : uint{/// <summary>/// Some other protocol not specified in RFC 1354./// </summary>MIB_IPPROTO_OTHER = 1,/// <summary>/// A local interface./// </summary>MIB_IPPROTO_LOCAL = 2,/// <summary>/// A static route. /// This value is used to identify route information for IP routing/// set through network management such as the Dynamic Host Configuration/// Protocol (DCHP), the Simple Network Management Protocol (SNMP),/// or by calls to the CreateIpForwardEntry, DeleteIpForwardEntry,/// or SetIpForwardEntry functions./// </summary>MIB_IPPROTO_NETMGMT = 3,/// <summary>/// The result of ICMP redirect./// </summary>MIB_IPPROTO_ICMP = 4,/// <summary>/// The Exterior Gateway Protocol (EGP), a dynamic routing protocol./// </summary>MIB_IPPROTO_EGP = 5,/// <summary>/// The Gateway-to-Gateway Protocol (GGP), a dynamic routing protocol./// </summary>MIB_IPPROTO_GGP = 6,/// <summary>/// The Hellospeak protocol, a dynamic routing protocol. This is a/// historical entry no longer in use and was an early routing protocol/// used by the original ARPANET routers that ran special software/// called the Fuzzball routing protocol, sometimes called Hellospeak,/// as described in RFC 891 and RFC 1305. For more information,/// see http://www.ietf.org/rfc/rfc891.txt and http://www.ietf.org/rfc/rfc1305.txt./// </summary>MIB_IPPROTO_HELLO = 7,/// <summary>/// The Berkeley Routing Information Protocol (RIP) or RIP-II, a dynamic routing protocol./// </summary>MIB_IPPROTO_RIP = 8,/// <summary>/// The Intermediate System-to-Intermediate System (IS-IS) protocol,/// a dynamic routing protocol. The IS-IS protocol was developed for/// use in the Open Systems Interconnection (OSI) protocol suite./// </summary>MIB_IPPROTO_IS_IS = 9,/// <summary>/// The End System-to-Intermediate System (ES-IS) protocol, a dynamic/// routing protocol. The ES-IS protocol was developed for use in the/// Open Systems Interconnection (OSI) protocol suite./// </summary>MIB_IPPROTO_ES_IS = 10,/// <summary>/// The Cisco Interior Gateway Routing Protocol (IGRP), a dynamic routing protocol./// </summary>MIB_IPPROTO_CISCO = 11,/// <summary>/// The Bolt, Beranek, and Newman (BBN) Interior Gateway Protocol/// (IGP) that used the Shortest Path First (SPF) algorithm. This/// was an early dynamic routing protocol./// </summary>MIB_IPPROTO_BBN = 12,/// <summary>/// The Open Shortest Path First (OSPF) protocol, a dynamic routing protocol./// </summary>MIB_IPPROTO_OSPF = 13,/// <summary>/// The Border Gateway Protocol (BGP), a dynamic routing protocol./// </summary>MIB_IPPROTO_BGP = 14,/// <summary>/// A Windows specific entry added originally by a routing protocol, but which is now static./// </summary>MIB_IPPROTO_NT_AUTOSTATIC = 10002,/// <summary>/// A Windows specific entry added as a static route from the routing user interface or a routing command./// </summary>MIB_IPPROTO_NT_STATIC = 10006,/// <summary>/// A Windows specific entry added as a static route from the routing/// user interface or a routing command, except these routes do not cause Dial On Demand (DOD)./// </summary>MIB_IPPROTO_NT_STATIC_NON_DOD = 10007}[StructLayout(LayoutKind.Sequential)]public struct MIB_IPFORWARDROW{public uint dwForwardDest;        //destination IP address.public uint dwForwardMask;        //Subnet maskpublic uint dwForwardPolicy;      //conditions for multi-path route. Unused, specify 0.public uint dwForwardNextHop;     //IP address of the next hop. Own address?public uint dwForwardIfIndex;     //index of interfacepublic MIB_IPFORWARD_TYPE dwForwardType;        //route typepublic MIB_IPPROTO dwForwardProto;       //routing protocol.public uint dwForwardAge;         //age of route.public uint dwForwardNextHopAS;   //autonomous system number. 0 if not relevantpublic int dwForwardMetric1;     //-1 if not used (goes for all metrics)public int dwForwardMetric2;public int dwForwardMetric3;public int dwForwardMetric4;public int dwForwardMetric5;}[StructLayout(LayoutKind.Sequential)]public struct MIB_IPINTERFACE_ROW{public uint Family;public ulong InterfaceLuid;public uint InterfaceIndex;public uint MaxReassemblySize;public ulong InterfaceIdentifier;public uint MinRouterAdvertisementInterval;public uint MaxRouterAdvertisementInterval;public byte AdvertisingEnabled;public byte ForwardingEnabled;public byte WeakHostSend;public byte WeakHostReceive;public byte UseAutomaticMetric;public byte UseNeighborUnreachabilityDetection;public byte ManagedAddressConfigurationSupported;public byte OtherStatefulConfigurationSupported;public byte AdvertiseDefaultRoute;public uint RouterDiscoveryBehavior;public uint DadTransmits;public uint BaseReachableTime;public uint RetransmitTime;public uint PathMtuDiscoveryTimeout;public uint LinkLocalAddressBehavior;public uint LinkLocalAddressTimeout;public uint ZoneIndice0, ZoneIndice1, ZoneIndice2, ZoneIndice3, ZoneIndice4, ZoneIndice5, ZoneIndice6, ZoneIndice7,ZoneIndice8, ZoneIndice9, ZoneIndice10, ZoneIndice11, ZoneIndice12, ZoneIndice13, ZoneIndice14, ZoneIndice15;public uint SitePrefixLength;public uint Metric;public uint NlMtu;public byte Connected;public byte SupportsWakeUpPatterns;public byte SupportsNeighborDiscovery;public byte SupportsRouterDiscovery;public uint ReachableTime;public byte TransmitOffload;public byte ReceiveOffload;public byte DisableDefaultRoutes;}[StructLayout(LayoutKind.Sequential)]private unsafe struct MIB_IPFORWARDTABLE{/// <summary>/// number of route entriesin the table./// </summary>public int dwNumEntries;public MIB_IPFORWARDROW table;}[DllImport("Iphlpapi.dll")][return: MarshalAs(UnmanagedType.U4)]private static extern int CreateIpForwardEntry(MIB_IPFORWARDROW pRoute);[DllImport("Iphlpapi.dll")][return: MarshalAs(UnmanagedType.U4)]private static extern int DeleteIpForwardEntry(MIB_IPFORWARDROW pRoute);[DllImport("Iphlpapi.dll")][return: MarshalAs(UnmanagedType.U4)]private static extern int SetIpForwardEntry(MIB_IPFORWARDROW pRoute);[DllImport("Iphlpapi.dll")]private static extern int GetIpInterfaceEntry(ref MIB_IPINTERFACE_ROW row);[DllImport("iphlpapi.dll", CharSet = CharSet.Auto)]private static extern int GetBestInterface(uint DestAddr, out uint BestIfIndex);[DllImport("Iphlpapi.dll")]private static extern int GetBestRoute(uint dwDestAddr, uint dwSourceAddr, out MIB_IPFORWARDROW pBestRoute);[DllImport("Iphlpapi.dll")][return: MarshalAs(UnmanagedType.U4)]private unsafe static extern int GetIpForwardTable(MIB_IPFORWARDTABLE* pIpForwardTable, ref int pdwSize, bool bOrder);[DllImport("Kernel32.dll")]private extern static int FormatMessage(int flag, ref IntPtr source, int msgid, int langid, ref string buf, int size, ref IntPtr args);/// <summary>/// 獲取錯誤信息/// </summary>/// <param name="errCode"></param>/// <returns></returns>public static string GetErrMsg(int errCode){IntPtr tempptr = IntPtr.Zero;string msg = null;FormatMessage(0x1300, ref tempptr, errCode, 0, ref msg, 255, ref tempptr);return msg;}/// <summary>/// 獲取路由表/// </summary>/// <param name="ipForwardTable"></param>/// <returns></returns>public unsafe static int GetIpForwardTable(out IPForwardRow[] ipForwardTable){int res = 0, size = 0;size = Marshal.SizeOf(typeof(MIB_IPFORWARDROW));MIB_IPFORWARDTABLE* table = (MIB_IPFORWARDTABLE*)Marshal.AllocHGlobal(size);res = GetIpForwardTable(table, ref size, true);if (res == 0x7A){table = (MIB_IPFORWARDTABLE*)Marshal.ReAllocHGlobal((IntPtr)table, (IntPtr)size);res = GetIpForwardTable(table, ref size, true);}if (res == 0){ipForwardTable = new IPForwardRow[(*table).dwNumEntries];for (int i = 0; i < ipForwardTable.Length; i++){ipForwardTable[i] = new IPForwardRow((&(*table).table)[i]);}}elseipForwardTable = null;Marshal.FreeHGlobal((IntPtr)table);return res;}/// <summary>/// 獲取基礎路由/// </summary>/// <param name="destAddr"></param>/// <param name="sourceAddr"></param>/// <param name="bestRoute"></param>/// <returns></returns>public static int GetBestRoute(IPAddress destAddr, IPAddress sourceAddr, out IPForwardRow bestRoute){MIB_IPFORWARDROW pBestRoute;var res = GetBestRoute(IpToUint(destAddr), IpToUint(sourceAddr), out pBestRoute);bestRoute = new IPForwardRow(pBestRoute);return res;}/// <summary>/// 獲取基礎接口/// </summary>/// <param name="destAddr"></param>/// <param name="bestIfIndex"></param>/// <returns></returns>public static int GetBestInterface(IPAddress destAddr, out uint bestIfIndex){return GetBestInterface(IpToUint(destAddr), out bestIfIndex);}/// <summary>/// 獲取IP接口信息/// </summary>/// <param name="interfaceIndex"></param>/// <param name="row"></param>/// <returns></returns>public static int GetIpInterfaceEntry(uint interfaceIndex, out MIB_IPINTERFACE_ROW row){row = new MIB_IPINTERFACE_ROW();row.Family = 2;//row.InterfaceLuid = 0;row.InterfaceIndex = interfaceIndex;return GetIpInterfaceEntry(ref row);}/// <summary>/// 獲取單條路由信息/// </summary>/// <param name="destAddr"></param>/// <param name="nextHop"></param>/// <param name="route"></param>/// <returns></returns>public unsafe static int GetIpForwardEntry(IPAddress destAddr, IPAddress nextHop, out IPForwardRow route){route = null;IPForwardRow[] ipForwardTable;var res = GetIpForwardTable(out ipForwardTable);if (res == 0){for (int i = 0; i < ipForwardTable.Length; i++){if (ipForwardTable[i].Dest.Equals(destAddr) && ipForwardTable[i].NextHop.Equals(nextHop)){route = ipForwardTable[i];break;}}}return res;}/// <summary>/// 獲取單條路由信息/// </summary>/// <param name="destAddr"></param>/// <param name="route"></param>/// <returns></returns>public unsafe static int GetIpForwardEntry(IPAddress destAddr, out IPForwardRow route){route = null;IPForwardRow[] ipForwardTable;var res = GetIpForwardTable(out ipForwardTable);if (res == 0){for (int i = 0; i < ipForwardTable.Length; i++){if (ipForwardTable[i].Dest.Equals(destAddr)){route = ipForwardTable[i];break;}}}return res;}/// <summary>/// 創建路由/// </summary>/// <param name="route"></param>/// <returns></returns>public static int CreateIpForwardEntry(IPForwardRow route){return CreateIpForwardEntry(route.GetBaseStruct());}/// <summary>/// 創建路由/// </summary>/// <param name="dest"></param>/// <param name="mask"></param>/// <param name="nextHop"></param>/// <param name="ifIndex"></param>/// <param name="metric"></param>/// <returns></returns>public static int CreateIpForwardEntry(IPAddress dest, IPAddress mask, IPAddress nextHop, uint ifIndex, int metric = 1){IPForwardRow route = new IPForwardRow(){Dest = dest,Mask = mask,NextHop = nextHop,IfIndex = ifIndex,Metric = metric,Policy = 0,Type = MIB_IPFORWARD_TYPE.MIB_IPROUTE_TYPE_DIRECT,Proto = MIB_IPPROTO.MIB_IPPROTO_NETMGMT,Age = 0,NextHopAS = 0};OperatingSystem os = Environment.OSVersion;if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6){MIB_IPINTERFACE_ROW row;int res = GetIpInterfaceEntry(ifIndex, out row);if (res != 0)return res;route.Metric = (int)row.Metric;}return CreateIpForwardEntry(route);}/// <summary>/// 創建路由/// </summary>/// <param name="dest"></param>/// <param name="mask"></param>/// <param name="nextHop"></param>/// <param name="metric"></param>/// <returns></returns>public static int CreateIpForwardEntry(IPAddress dest, IPAddress mask, IPAddress nextHop, int metric = 1){uint bestIfIndex;int res = GetBestInterface(nextHop, out bestIfIndex);if (res != 0)return res;return CreateIpForwardEntry(dest, mask, nextHop, bestIfIndex, metric);}/// <summary>/// 創建路由/// </summary>/// <param name="dest"></param>/// <param name="nextHop"></param>/// <param name="metric"></param>/// <returns></returns>public static int CreateIpForwardEntry(IPAddress dest, IPAddress nextHop, int metric = 1){return CreateIpForwardEntry(dest, IPAddress.Parse("255.255.255.255"), nextHop, metric);}/// <summary>/// [不推薦使用]修改路由/// 僅用于修改網關和躍點數/// </summary>/// <param name="route"></param>/// <returns></returns>public static int SetIpForwardEntry(IPForwardRow route){return SetIpForwardEntry(route.GetBaseStruct());}/// <summary>/// 刪除路由/// </summary>/// <param name="route"></param>/// <returns></returns>public static int DeleteIpForwardEntry(IPForwardRow route){return DeleteIpForwardEntry(route.GetBaseStruct());}/// <summary>/// 刪除路由/// </summary>/// <param name="destAddr"></param>/// <param name="nextHop"></param>/// <returns></returns>public static int DeleteIpForwardEntry(IPAddress destAddr, IPAddress nextHop){IPForwardRow route;int res = GetIpForwardEntry(destAddr, nextHop, out route);if (res != 0)return res;return DeleteIpForwardEntry(route);}/// <summary>/// 刪除路由/// </summary>/// <param name="destAddr"></param>/// <returns></returns>public static int DeleteIpForwardEntry(IPAddress destAddr){IPForwardRow route;int res = GetIpForwardEntry(destAddr, out route);if (res != 0)return res;return DeleteIpForwardEntry(route);}/// <summary>/// IPAdderss轉uint/// </summary>/// <param name="ipAddress"></param>/// <returns></returns>public static uint IpToUint(IPAddress ipAddress){string[] startIP = ipAddress.ToString().Split('.');uint U = uint.Parse(startIP[3]) << 24;U += uint.Parse(startIP[2]) << 16;U += uint.Parse(startIP[1]) << 8;U += uint.Parse(startIP[0]);return U;}/// <summary>/// uint轉IPAddress/// </summary>/// <param name="ip"></param>/// <returns></returns>public static IPAddress UintToIp(uint ip){string ipStr = $"{ip & 0xff}.{(ip >> 8) & 0xff}.{(ip >> 16) & 0xff}.{(ip >> 24) & 0xff}";return IPAddress.Parse(ipStr);}}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;namespace RBTI.Toolbox.RasConnect.Network
{class IPForwardRow{/// <summary>/// destination IP address./// </summary>public IPAddress Dest { get; set; }/// <summary>/// Subnet mask/// </summary>public IPAddress Mask { get; set; }/// <summary>/// conditions for multi-path route. Unused, specify 0./// </summary>public uint Policy { get; set; }/// <summary>/// IP address of the next hop. Own address?/// </summary>public IPAddress NextHop { get; set; }/// <summary>/// index of interface/// </summary>public uint IfIndex { get; set; }/// <summary>/// route type/// </summary>public RouteTableManager.MIB_IPFORWARD_TYPE Type { get; set; }/// <summary>/// routing protocol./// </summary>public RouteTableManager.MIB_IPPROTO Proto { get; set; }/// <summary>/// age of route./// </summary>public uint Age { get; set; }/// <summary>/// autonomous system number. 0 if not relevant/// </summary>public uint NextHopAS { get; set; }/// <summary>/// -1 if not used (goes for all metrics)/// </summary>public int Metric { get; set; }public IPForwardRow(){}public IPForwardRow(RouteTableManager.MIB_IPFORWARDROW baseStruct){Dest = RouteTableManager.UintToIp(baseStruct.dwForwardDest);Mask = RouteTableManager.UintToIp(baseStruct.dwForwardMask);Policy = baseStruct.dwForwardPolicy;NextHop = RouteTableManager.UintToIp(baseStruct.dwForwardNextHop);IfIndex = baseStruct.dwForwardIfIndex;Type = baseStruct.dwForwardType;Proto = baseStruct.dwForwardProto;Age = baseStruct.dwForwardAge;NextHopAS = baseStruct.dwForwardNextHopAS;Metric = baseStruct.dwForwardMetric1;}public RouteTableManager.MIB_IPFORWARDROW GetBaseStruct(){return new RouteTableManager.MIB_IPFORWARDROW(){dwForwardDest = RouteTableManager.IpToUint(Dest),dwForwardMask = RouteTableManager.IpToUint(Mask),dwForwardPolicy = Policy,dwForwardNextHop = RouteTableManager.IpToUint(NextHop),dwForwardIfIndex = IfIndex,dwForwardType = Type,dwForwardProto = Proto,dwForwardAge = Age,dwForwardNextHopAS = NextHopAS,dwForwardMetric1 = Metric,dwForwardMetric2 = -1,dwForwardMetric3 = -1,dwForwardMetric4 = -1,dwForwardMetric5 = -1};}}
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/386954.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/386954.shtml
英文地址,請注明出處:http://en.pswp.cn/news/386954.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

RUNOOB python練習題9 如何在代碼中加入砸瓦魯多

用來練手的python 練習題&#xff0c;原鏈接 : python練習實例9 題干: 暫停一秒輸出 如何在輸出的過程中加入咋瓦魯多&#xff0c;讓輸出更有節奏感&#xff0c;滿足需求呢&#xff1f; import time import numpy as nptable np.arange(0,10,1,dtypeint) for i in range(tab…

服務器與客戶端連接 聊天機器人

服務器運行當顯示 E:\pycharm\python\venv\Scripts\python.exe E:/pycharm/python/協議/機器人聊天服務器.py 開始監聽 accept 說明服務器運行成功 之后運行客戶端&#xff0c;輸入“命令” E:\pycharm\python\venv\Scripts\python.exe E:/pycharm/python/協議/機器人聊天客戶…

Fiddler抓取https設置及其原理

Fiddler抓取https設置及其原理 2018-02-02 目錄 1 HTTPS握手過程 2 Fiddler抓取HTTPS過程 3 Fiddler抓取HTTPS設置參考 數字簽名是什么&#xff1f; 1 HTTPS握手過程 HTTPS 并非是應用層的一種新協議。只是 HTTP 通信接口部分用 SSL &#xff08;安全套接字層&#xff09;和…

springboot 返回json字符串格式化問題

在idea中yml文件中添加以下注解就可以格式化json字符串效果 spring: jackson: serialization: indent-output: true 原返回json格式為&#xff1a; {"isSuccess":"ok","code":"0","message":"success",&…

RUNOOB python練習題10

用來練手的python 練習題&#xff0c;原鏈接 : python練習實例9 題干 : 暫停兩秒輸出&#xff0c;并格式化當前時間。 import time,datetimeTIME datetime.datetime.now() print(TIME.strftime("%Y.%m.%d %H-%M-%S")) time.sleep(2) TIME datetime.datetime.now(…

HTTPS連接過程以及中間人攻擊劫持

HTTPS連接過程以及中間人攻擊劫持 目前很多應用都用webview加載H5頁面&#xff0c;如果服務端采用的是可信CA頒發的證書&#xff0c;在 webView.setWebViewClient(webviewClient) 時重載 WebViewClient的onReceivedSslError() &#xff0c;如果出現證書錯誤&#xff0c;直接調…

Cookie、cookie使用方法

Cookie、cookie使用方法、保存用戶名密碼 //設置Cookie&#xff0c;//cname 獲取時所需參數//username,password 用于記住賬號密碼&#xff0c;如果只要存一個參數 password為空即可//exdays 設置過期參數 設為負數即可刪除&#xff08;如-1&#xff09;function setCookie(c…

RUNOOB python練習題12 找素數問題

用來練手的python 練習題&#xff0c;原鏈接 : python練習實例12 題干 : 判斷101-200之間有多少個素數&#xff0c;并輸出所有素數 源代碼如下: import numpy as np bound np.arange(101,201,1) result np.array([]) for k in bound:for i in range(k):# 如果k存在不是1或…

Linux: centOS6.5 RabbitMQ

在大多數大公司&#xff0c;像應用服務器軟件的安裝、部署都是運維的事情&#xff0c;其實自己去嘗試部署一下&#xff0c;也是有收獲的。 有機會正好嘗試了Linux下的rabbitMq安裝過程&#xff0c;做了記錄&#xff0c;希望有用到的人可以做下參考。 安裝環境&#xff1a; Li…

RUNOOB python練習題13 水仙花數

用來練手的python 練習題其十三&#xff0c;原鏈接 : python練習實例13 題干 : 打印出所有的"水仙花數"&#xff0c;所謂"水仙花數"是指一個三位數&#xff0c;其各位數字立方和等于該數本身。例如&#xff1a;153是一個"水仙花數"&#xff0c;…

OsharpNS輕量級.net core快速開發框架簡明入門教程-代碼生成器的使用

OsharpNS輕量級.net core快速開發框架簡明入門教程 教程目錄 從零開始啟動Osharp 1.1. 使用OsharpNS項目模板創建項目 1.2. 配置數據庫連接串并啟動項目 1.3. OsharpNS.Swagger使用實例(登錄和授權) 1.4. Angular6的前端項目啟動Osharp代碼生成器的使用 2.1 生成器的使用 2.2 生…

RUNOOB python練習題 14

用來練手的python 練習題其十四&#xff0c;原鏈接 : python練習實例14 題干 : 將一個正整數分解質因數。例如&#xff1a;輸入90,打印出90233*5。 拿到題目&#xff0c;我們就可以看出&#xff0c;首先我們需要一個函數來判斷某一正整數是否為質數&#xff0c;然后還需要一個…

關于作者

北京某公司滲透工程師 Web滲透、PHP/Java代碼審計、安全研究 想換一份工作&#xff0c;求推薦。轉載于:https://www.cnblogs.com/dgjnszf/p/10779097.html

centos7通過yum安裝JDK1.8

安裝之前先檢查一下系統有沒有自帶open-jdk 命令&#xff1a; rpm -qa |grep java rpm -qa |grep jdk rpm -qa |grep gcj 如果沒有輸入信息表示沒有安裝。 如果安裝可以使用rpm -qa | grep java | xargs rpm -e --nodeps 批量卸載所有帶有Java的文件 這句命令的關鍵字是j…

一個電腦的重裝到java開發環境安裝配置的全過程

剛拿到一臺別人用過的電腦。看著c盤爆滿&#xff0c;而且用了還是windows7操作系統&#xff0c;強迫癥發作馬上就準備重裝系統。 之前換固態使用wepe制作U盤啟動盤裝系統的步驟和過程全部忘記的&#xff0c;賊尷尬。 同事都看不過眼了 使用UltraISO這個軟件幫我做了U盤啟動盤 …

RUNOOB python練習題17

用來練手的python 練習題其十三&#xff0c;原鏈接 : python練習實例17 題干 : 輸入一行字符&#xff0c;分別統計出其中英文字母、空格、數字和其它字符的個數 這個例題讓我回憶起了遠古的記憶&#xff0c;python str類的 isalpha,isspace,isdigit方法。這些方法通過比較ASC…

Centos7下使用ELK(Elasticsearch + Logstash + Kibana)搭建日志集中分析平臺

Centos7下使用ELK&#xff08;Elasticsearch Logstash Kibana&#xff09;搭建日志集中分析平臺 日志監控和分析在保障業務穩定運行時&#xff0c;起到了很重要的作用&#xff0c;不過一般情況下日志都分散在各個生產服務器&#xff0c;且開發人員無法登陸生產服務器&#xf…

疊數的加法與字符串 RUNOOB python練習題 18

用來練手的python 練習題其十八&#xff0c;原鏈接 : python練習實例18 題干: 求saaaaaaaaaaaa…a的值&#xff0c;其中a是一個數字。例如222222222222222(此時共有5個數相加)&#xff0c;幾個數相加由鍵盤控制 這種類型的疊數相加&#xff0c;讓我不禁聯想到了python中&…

wget在linux中安裝出現錯誤解決辦法

在使用wget命令報錯 certificate common name xxx doesnt match requestde host name&#xff0c;我們一般的解決辦法是查找下載地址&#xff0c;但是有時候更換地址也會發生錯誤&#xff0c; wget http://www.monkey.org/~provos/libevent-1.2.tar.gz 報如下錯&#xff1a; er…

linux下elasticsearch的安裝

首先安裝jdk 下載elasticsearch wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz 解壓 tar -zxvf elasticsearch-6.2.4.tar.gz 移動項目到/usr目錄下 mv elasticsearch-6.2.4 /usr 啟動es /usr/elasticsearch-6.4.2/bin/elastic…