当前位置: 首页 > wzjs >正文

多店铺开源商城系统搜索引擎营销优化策略有哪些

多店铺开源商城系统,搜索引擎营销优化策略有哪些,软件工程师报考条件,凡科做数据查询网站在很多场景中需要获取到终端设备的一些硬件信息等,获取的字段如下: 返回参数 参数含义备注systemName系统名称remoteIp公网iplocalIp本地ip取IPV4macmac地址去掉地址中的"-“或”:"进行记录cpuSerialcpu序列号hardSerial硬盘序列号drive盘符…
  • 在很多场景中需要获取到终端设备的一些硬件信息等,获取的字段如下:

返回参数

参数含义备注
systemName系统名称
remoteIp公网ip
localIp本地ip取IPV4
macmac地址去掉地址中的"-“或”:"进行记录
cpuSerialcpu序列号
hardSerial硬盘序列号
drive盘符C
fileSystem分区格式NTFS
partitionSize分区容量119G
systemDisk系统盘卷标号
pcNamePC终端设备名称
pcSerialPC终端设备序列号仅Mac系统有,其余系统返回"null"
public final class HardInfoUtils {private static final Logger LOGGER = LoggerFactory.getLogger(HardInfoUtils.class);/*** 获取系统名称-systemName** @return 系统名称*/public static String getSystemName() {return System.getProperty("os.name");}/*** 获取本地IP-localIp** @return 本机 IP 地址* @throws RuntimeException 如果无法获取 IP 地址*/public static String getLocalIp() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统:使用 WMI 查询 IP 地址return getWindowsLocalIp();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统:使用 ifconfig 命令return getLinuxLocalIp();} else if (os.contains("mac")) {// MacOS 系统:使用 ifconfig 命令return getMacLocalIp();} else {throw new RuntimeException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get localIp", e);}}/*** 获取公网 IP** @return 公网 IP 地址,如果获取失败或格式不正确则返回 null*/public static String getRemoteIp() {String os = System.getProperty("os.name").toLowerCase();String command = "curl ifconfig.me";if (os.contains("win")) {return executeWindowsCommand(command, ip -> {if (ip != null && isValidIp(ip)) {return ip.trim();} else {LOGGER.error("IP format is incorrect or null: {}", ip);return null;}});} else {return executeCommandAndParseOutput(command, ip -> {if (ip != null && isValidIp(ip)) {return ip.trim();} else {LOGGER.error("IP format is incorrect or null: {}", ip);return null;}});}}/*** Windows 系统:获取本地 IP 地址** @return 本地 IP 地址*/private static String getWindowsLocalIp() {String command = "wmic nicconfig where IPEnabled=true get IPAddress";return executeWindowsCommand(command, line -> {if (line.contains(".")) {String[] parts = line.split(",");for (String part : parts) {part = part.replaceAll("[{}\"]", "").trim();if (isValidIp(part)) {return part;}}}return null;});}/*** 检查 IP 地址是否有效** @param ip IP 地址* @return 是否有效*/private static boolean isValidIp(String ip) {String ipv4Regex = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";Pattern pattern = Pattern.compile(ipv4Regex);Matcher matcher = pattern.matcher(ip);return matcher.matches();}/*** Linux 系统:获取本地 IP 地址** @return 本地 IP 地址*/private static String getLinuxLocalIp() {String command ="ifconfig | grep -E 'flags=|inet |broadcast ' | grep -i RUNNING -A 1 | grep 'inet ' | grep -m 1 " +"'broadcast ' | awk '{print $2}'";return executeCommandAndParseOutput(command, line -> line);}/*** MacOS 系统:获取本地 IP 地址** @return 本地 IP 地址*/private static String getMacLocalIp() {String command ="ifconfig | grep -E 'flags=|inet |broadcast ' | grep -i RUNNING -A 1 | grep 'inet ' | grep -m 1 " +"'broadcast ' | awk '{print $2}'";return executeCommandAndParseOutput(command, line -> line);}/*** 执行 Windows 命令并解析输出** @param command         命令* @param outputProcessor 输出处理函数* @return 处理后的输出结果* @throws IOException IO 异常*/private static String executeWindowsCommand(String command, Function<String, String> outputProcessor) {try {Process process = Runtime.getRuntime().exec(command);try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {String line;while ((line = reader.readLine()) != null) {String result = outputProcessor.apply(line.trim());if (result != null) {return result;}}}} catch (IOException e) {throw new RuntimeException("Failed to execute command: " + command, e);}return null;}/*** Linux或MacOS下执行命令并解析输出** @param command 命令* @return 输出结果*/private static String executeCommandAndParseOutput(String command, Function<String, String> outputProcessor) {try {Process process = Runtime.getRuntime().exec(new String[]{"sh", "-c", command});try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {String line;while ((line = reader.readLine()) != null) {if (!line.trim().isEmpty()) {String out = outputProcessor.apply(line.trim());if (out != null) {return out;}}}}} catch (IOException e) {throw new RuntimeException("Failed to execute command: " + command, e);}return null;}/*** 获取本机 MAC 地址-mac** @return 本机 MAC 地址*/public static String getMac() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统:使用 WMI 查询 MAC 地址return formatMac(getWindowsMac());} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统:使用 ifconfig 命令return formatMac(getLinuxMac());} else if (os.contains("mac")) {// MacOS 系统:使用 ifconfig 命令return formatMac(getMacOSMac());} else {throw new RuntimeException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get MAC address", e);}}/*** 格式化 MAC 地址为无分隔符的形式** @param mac MAC 地址* @return 无分隔符的 MAC 地址*/private static String formatMac(String mac) {if (mac == null || mac.isEmpty()) {return "";}// 移除所有分隔符(如 ":", "-")return mac.replaceAll("[:\\-]", "");}/*** Windows 系统:获取 MAC 地址** @return MAC 地址*/private static String getWindowsMac() {// 筛选出物理适配器,并且是已启用的状态String command = "wmic nic where \"PhysicalAdapter=True and NetEnabled=True\" get MACAddress /format:value";return executeWindowsCommand(command, line -> {if (line.startsWith("MACAddress=") && line.length() > "MACAddress=".length()) {// 清除前缀String macAddress = line.substring("MACAddress=".length()).trim();return macAddress.replace(":", "-");}return null;});}/*** Linux 系统:获取 MAC 地址** @return MAC 地址*/private static String getLinuxMac() {String command ="ifconfig | grep -E 'flags=|inet |broadcast |ether ' | grep -i RUNNING -A 2 | grep -A 1 -E 'broadcast" +" " + "|inet ' | grep -m 1 'ether ' | awk '{print $2}'";return executeCommandAndParseOutput(command, line -> line);}/*** MacOS 系统:获取 MAC 地址** @return MAC 地址*/private static String getMacOSMac() {String command ="ifconfig | grep -E 'flags=|inet |broadcast |ether ' | grep -i RUNNING -A 2 | grep -B 1 -E 'broadcast" +" " + "|inet ' | grep -m 1 'ether ' | awk '{print $2}'";return executeCommandAndParseOutput(command, line -> line);}/*** 获取CPU序列号-cpuSerial** @return CPU 序列号*/public static String getCpuSerial() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统:使用 wmic 命令获取 CPU 序列号return getWindowsCpuSerial();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统:使用 dmidecode 命令获取 CPU 序列号return getLinuxCpuSerial();} else if (os.contains("mac")) {// macOS 系统:使用 system_profiler 命令获取 CPU 序列号return getMacCpuSerial();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get cpuSerial", e);}}/*** Windows 系统:获取 CPU 序列号** @return CPU 序列号*/private static String getWindowsCpuSerial() {String command = "wmic cpu get ProcessorId";return executeWindowsCommand(command, line -> {if (!line.isEmpty() && !line.contains("ProcessorId")) {return line;}return null;});}/*** Linux 系统:获取 CPU 序列号** @return CPU 序列号*/private static String getLinuxCpuSerial() {String command = "dmidecode -t 4 | grep -m 1 ID | awk '{print $2$3$4$5$6$7$8$9}'";return executeCommandAndParseOutput(command, line -> {// 去掉所有空格String cpuSerial = line.replaceAll("\\s+", "");// 如果 CPU 序列号全为 0,则返回 nullif ("0000000000000000".equals(cpuSerial)) {return null;}return cpuSerial;});}/*** macOS 系统:获取 CPU 序列号** @return CPU 序列号*/private static String getMacCpuSerial() {String command = "system_profiler SPHardwareDataType | grep -m 1 'Serial Number' | awk '{print $4}'";return executeCommandAndParseOutput(command, line -> {// 去掉所有空格return line.trim().replaceAll("\\s+", "");});}/*** 获取硬盘序列号-hardSerial** @return 硬盘序列号*/public static String getHardSerial() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统return getWindowsHardSerial();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统return getLinuxHardSerial();} else if (os.contains("mac")) {// macOS 系统return getMacHardSerial();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get hardSerial", e);}}/*** Windows 系统:获取硬盘序列号** @return 硬盘序列号,如:6479_A75B_B090_09E0*/private static String getWindowsHardSerial() {String command = "wmic diskdrive get serialnumber";return executeWindowsCommand(command, line -> {if (!line.trim().isEmpty() && !line.contains("SerialNumber")) {// 去掉末尾的点(如果存在)return line.trim().endsWith(".") ? line.trim().substring(0, line.length() - 1) : line.trim();}return null;});}/*** Linux 系统:获取硬盘序列号** @return 硬盘序列号,如:ac7b3398-162e-4775-b*/private static String getLinuxHardSerial() {// Linux amd 执行后:SERIAL=""String command ="lsblk -p -P -o NAME,SERIAL,UUID,TYPE,MOUNTPOINT | grep -i boot -B 1 | grep -i disk | awk '{print $2}'";return executeCommandAndParseOutput(command, line -> {String result = line.trim().replace("SERIAL=", "").replace("\"", "");// 去掉末尾的点(如果存在)if (result.endsWith(".")) {result = result.substring(0, result.length() - 1);}// 如果序列号为空,返回 nullreturn result.isEmpty() ? null : result;});}/*** macOS 系统:获取硬盘序列号** @return 硬盘序列号*/private static String getMacHardSerial() {String command = "system_profiler SPHardwareDataType | grep -m 1 'Hardware UUID' | awk '{print $3}'";return executeCommandAndParseOutput(command, line -> {String result = line.trim();// 去掉末尾的点(如果存在)if (result.endsWith(".")) {result = result.substring(0, result.length() - 1);}return result;});}/*** 获取系统盘盘符-drive** @return 系统盘盘符,如:C 或 /dev/sda1* @throws RuntimeException 获取失败时抛出异常*/public static String getDrive() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统return getWindowsDrive();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统return getLinuxDrive();} else if (os.contains("mac")) {// macOS 系统return getMacDrive();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get drive", e);}}/*** Windows 系统:获取盘符** @return 盘符,如:C*/private static String getWindowsDrive() {// 获取系统盘盘符(如 C:)String systemDrive = System.getenv("SystemDrive");if (systemDrive == null || systemDrive.isEmpty()) {LOGGER.error("SystemDrive environment variable is empty");return null;}// 去掉冒号return systemDrive.replace(":", "");}/*** Linux 系统:获取盘符** @return 盘符,如:/dev/sda1*/private static String getLinuxDrive() {String command ="lsblk -p -P -o NAME,PARTUUID,FSTYPE,SIZE,UUID,TYPE,MOUNTPOINT | grep -E '/boot\"$' | grep -i part | " +"awk " + "'{print $1,$2,$3,$4}'";return executeCommandAndParseOutput(command, line -> {String[] split = line.split("\"");return split.length > 1 ? split[1] : null;});}/*** macOS 系统:获取盘符** @return 盘符*/private static String getMacDrive() {String command = "system_profiler SPSoftwareDataType | grep -m 1 'Boot Volume'";return executeCommandAndParseOutput(command, line -> {String[] split = line.split(": ");return split.length > 1 ? split[1] : null;});}/*** 获取系统盘分区格式-fileSystem** @return 系统盘分区格式,如:NTFS 或 xf4* @throws RuntimeException 如果无法获取分区格式*/public static String getFileSystem() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统return getWindowsFileSystem();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统return getLinuxFileSystem();} else if (os.contains("mac")) {// macOS 系统return getMacFileSystem();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get fileSystem", e);}}/*** Windows 系统:获取分区格式** @return 分区格式,如:NTFS*/private static String getWindowsFileSystem() {// 获取系统盘盘符(如 C:)String systemDrive = System.getenv("SystemDrive");if (systemDrive == null || systemDrive.isEmpty()) {LOGGER.error("SystemDrive environment variable is empty");return null;}// 获取系统盘的分区信息String command = "wmic logicaldisk where deviceid='" + systemDrive + "' get filesystem";return executeWindowsCommand(command, line -> {if (!line.isEmpty() && !line.contains("FileSystem")) {return line;}return null;});}/*** Linux 系统:获取分区格式** @return 分区格式*/private static String getLinuxFileSystem() {String command ="lsblk -p -P -o NAME,PARTUUID,FSTYPE,SIZE,UUID,TYPE,MOUNTPOINT | grep -E '/boot\"$' | grep -i part | " +"awk " + "'{print $1,$2,$3,$4}'";return executeCommandAndParseOutput(command, line -> {String[] split = line.split("\"");return split.length > 5 ? split[5] : null;});}/*** macOS 系统:获取分区格式** @return 分区格式*/private static String getMacFileSystem() {String command = "system_profiler SPStorageDataType | grep -w -A 5 -B 1 'Mount Point: /'";return executeCommandAndParseOutput(command, line -> {String number = "";String[] lines = line.split("\n");for (String l : lines) {l = l.trim();if (l.startsWith("File System:")) {String[] split = l.split(" ");if (split.length > 2) {number = split[2];}}}return number.isEmpty() ? null : number;});}/*** 获取系统盘分区容量** @return 系统盘分区容量,如:119G* @throws RuntimeException 如果无法获取分区容量*/public static String getPartitionSize() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统return getWindowsPartitionSize();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统return getLinuxPartitionSize();} else if (os.contains("mac")) {// macOS 系统return getMacPartitionSize();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get partition size", e);}}/*** Windows 系统:获取分区容量** @return 分区容量*/private static String getWindowsPartitionSize() {// 获取系统盘盘符(如 C:)String systemDrive = System.getenv("SystemDrive");if (systemDrive == null || systemDrive.isEmpty()) {LOGGER.error("SystemDrive environment variable is empty");return null;}// 获取系统盘的分区信息String command = "wmic logicaldisk where deviceid='" + systemDrive + "' get size";return executeWindowsCommand(command, line -> {if (!line.isEmpty() && !line.contains("Size")) {long sizeBytes = Long.parseLong(line);return (sizeBytes / 1024 / 1024 / 1024) + "G";}return null;});}/*** Linux 系统:获取分区容量** @return 分区容量*/private static String getLinuxPartitionSize() {String command ="lsblk -p -P -o NAME,PARTUUID,FSTYPE,SIZE,UUID,TYPE,MOUNTPOINT | grep -E '/boot\"$' | grep -i part | " +"awk " + "'{print $1,$2,$3,$4}'";return executeCommandAndParseOutput(command, output -> {String[] split = output.split("\"");return split.length > 7 ? split[7] : null;});}/*** macOS 系统:获取分区容量** @return 分区容量*/private static String getMacPartitionSize() {String command = "system_profiler SPStorageDataType | grep -w -A 5 -B 1 'Mount Point: /'";return executeCommandAndParseOutput(command, line -> {String size = "";String[] lines = line.split("\n");for (String l : lines) {l = l.trim();if (l.startsWith("Capacity:")) {String[] split = l.split(" ");if (split.length > 1) {size = split[1] + "G";}}}return size;});}/*** 获取系统盘卷标号-systemDisk** @return 系统盘卷标号*/public static String getSystemDisk() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统return getWindowsSystemDisk();} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统return getLinuxSystemDisk();} else if (os.contains("mac")) {// macOS 系统return getMacSystemDisk();} else {throw new UnsupportedOperationException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get systemDisk", e);}}/*** Windows 系统:获取系统盘卷标号** @return 系统盘卷标号,格式为 "XXXX-XXXX",如:8AD0-CC8B*/private static String getWindowsSystemDisk() {// 获取系统盘盘符(如 C:)String systemDrive = System.getenv("SystemDrive");if (systemDrive == null || systemDrive.isEmpty()) {LOGGER.error("SystemDrive environment variable is empty");return null;}// 获取系统盘的卷标号String command = "wmic logicaldisk where deviceid='" + systemDrive + "' get VolumeSerialNumber";return executeWindowsCommand(command, line -> {if (!line.isEmpty() && !line.contains("VolumeSerialNumber")) {if (line.length() == 8) {// 格式化为 XXXX-XXXXreturn line.substring(0, 4) + "-" + line.substring(4);}}return null;});}/*** Linux 系统:获取系统盘卷标号** @return 系统盘卷标号*/private static String getLinuxSystemDisk() {// 使用 lsblk 命令获取系统盘卷标号// Linux amd执行后:UUID="" LABEL=""String command ="lsblk -p -P -o NAME,UUID,LABEL,TYPE,MOUNTPOINT | grep -i boot -B 1 | grep -i disk | awk '{print $2," +"$3}'";return executeCommandAndParseOutput(command, line -> {String[] parts = line.trim().split("\"");if (parts.length >= 4) {// UUIDString uuid = parts[1];// LABELString label = parts[3];// 返回 UUID 或 LABELreturn !uuid.isEmpty() ? uuid : label;}return null;});}/*** macOS 系统:获取系统盘卷标号** @return 系统盘卷标号*/private static String getMacSystemDisk() {String command = "system_profiler SPStorageDataType | grep -w -A 5 -B 1 'Mount Point: /'";return executeCommandAndParseOutput(command, line -> {String number = "";String[] lines = line.split("\n");for (String l : lines) {l = l.trim();if (l.startsWith("Volume UUID:")) {String[] split = l.split(" ");if (split.length > 2) {number = split[2];}}}return number.isEmpty() ? null : number;});}/*** 获取PC终端设备名称-pcName** @return PC终端设备名称*/public static String getPcName() {String os = System.getProperty("os.name").toLowerCase();try {if (os.contains("win")) {// Windows 系统:使用 hostname 命令获取设备名称String command = "hostname";return executeWindowsCommand(command, line -> line.isEmpty() ? null : line);} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {// Linux 系统:使用 hostname 命令获取设备名称return executeCommandAndParseOutput("hostname", line -> line);} else if (os.contains("mac")) {// MacOS 系统:使用 scutil 命令获取设备名称return executeCommandAndParseOutput("scutil --get ComputerName", line -> line);} else {throw new RuntimeException("Unsupported operating system: " + os);}} catch (Exception e) {throw new RuntimeException("Failed to get pcName.", e);}}/*** 获取PC终端设备序列号(仅 Mac 系统有,其他系统返回 "null")** @return PC 终端设备序列号,如果获取失败或非 Mac 系统则返回 "null"*/public static String getPcSerial() {String os = System.getProperty("os.name").toLowerCase();if (!os.contains("mac")) {// 非 Mac 系统直接返回 "null"return "null";}try {// MacOS 系统:使用 system_profiler 命令获取设备序列号String command = "system_profiler SPHardwareDataType | grep -m 1 'Provisioning UDID' | awk '{print $3}'";return executeCommandAndParseOutput(command, line -> line);} catch (Exception e) {throw new RuntimeException("Failed to get pcSerial on MacOS.", e);}}}
  • 测试下本地Windows
public class HardInfoUtilsTest {public static void main(String[] args) {System.out.println("systemName: " + HardInfoUtils.getSystemName());System.out.println("localIp: " + HardInfoUtils.getLocalIp());System.out.println("remoteIp: " + HardInfoUtils.getRemoteIp());System.out.println("mac: " + HardInfoUtils.getMac());System.out.println("cpuSerial: " + HardInfoUtils.getCpuSerial());System.out.println("hardSerial: " + HardInfoUtils.getHardSerial());System.out.println("drive: " + HardInfoUtils.getDrive());System.out.println("fileSystem: " + HardInfoUtils.getFileSystem());System.out.println("partitionSize: " + HardInfoUtils.getPartitionSize());System.out.println("systemDisk: " + HardInfoUtils.getSystemDisk());System.out.println("pcName: " + HardInfoUtils.getPcName());System.out.println("pcSerial: " + HardInfoUtils.getPcSerial());}}

在这里插入图片描述

http://www.dtcms.com/wzjs/244605.html

相关文章:

  • 温州做网站整站优化央视网新闻
  • 公司刚做网站在那里找图片做公司网站设计模板
  • 泰州建设企业网站优秀网站设计
  • 好看的页面自媒体seo是什么意思
  • 南京cms模板建站免费宣传平台
  • 如何做网站反链seo排名点击工具
  • 工商注册登记网qq群怎么优化排名靠前
  • 国内优秀的设计网站种子资源地址
  • 零基础 网站b2b网站免费推广
  • 网页设计各个部分的尺寸南宁百度seo排名
  • 北京大兴企业网站建设哪家好杭州网站
  • 自己怎么做网站的聚合页面免费外链工具
  • 大连精美网站制作百度竞价多少钱一个点击
  • wordpress 版权信息搜云seo
  • 做增员的保险网站网页设计友情链接怎么做
  • 中职国示范建设网站昆明seo
  • 宝鸡企业做网站优化设计七年级上册数学答案
  • 苏州 网站制作公司南昌seo招聘信息
  • 通过做政府门户网站的实验获得什么专业的google推广公司
  • 伴奏在线制作网站在线外链
  • 网站刚通过备案网站免费优化
  • cms网站开发模式推广网上国网
  • 天津网站开发网站360免费建站系统
  • 网站seo怎么做知乎一链一网一平台
  • 免费网站建设软件南宁网站seo排名优化
  • 北京丰台区网站建设公司百度升级最新版本下载安装
  • 设计一个简单的旅游网站免费网站注册平台
  • 凡科做的微网站怎样连接公众号seo结算系统
  • 网站建设公司倒闭网站内容优化方法
  • 做网站还是做公众号南宁网站建设网络公司