zoukankan      html  css  js  c++  java
  • NSIS检测端口是否被占用

    !include LogicLib.nsh

    !define AF_INET         2
    !define SOCK_STREAM     1
    !define IPPROTO_TCP     6

    Section
    ;Initialize Winsock
    System::Alloc 400
    Pop $0
    System::Call Ws2_32::WSAStartup(i514,ir0)i.r1
    StrCmp $1 0 0 done

    ;Create a SOCKET for listening for incoming connection requests
    System::Call Ws2_32::socket(i${AF_INET},i${SOCK_STREAM},i${IPPROTO_TCP})i.r1
    StrCmp $1 Cleanup
    System::Call Ws2_32::inet_addr(t"127.0.0.1")i.s
    System::Call Ws2_32::htons(i80)i.s
    System::Call "*(&i2 ${AF_INET}, &i2 s, i s, &t8) i.r2"
    ;Bind the socket.
    System::Call Ws2_32::bind(ir1,ir2,i16)i.r3
    ${If} $3 = -1
    MessageBox MB_ICONINFORMATION|MB_OK "bind() failed."
    System::Call Ws2_32::WSAGetLastError()i.r3
      ${If} $3 10048
        MessageBox MB_ICONINFORMATION|MB_OK "80端口被占用"
      ${EndIf}
    ${EndIf}
    System::Call Ws2_32::closesocket(ir1)
    System::Free $2
    Cleanup:
    System::Call Ws2_32::WSACleanup()
    done:
    System::Free $0
    SectionEnd

  • 相关阅读:
    [luoguP2622] 关灯问题II(状压最短路)
    [luoguP2016] 战略游戏(DP)
    FileUpload
    Mysql -- JDBC
    Mysql优化
    Mysql锁
    Mysql索引
    Mysql事务
    Mysql基本语句
    Listener
  • 原文地址:https://www.cnblogs.com/juin/p/2592071.html
Copyright © 2011-2022 走看看