杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2051|回复: 0

NSIS检测端口是否被占用

[复制链接]
发表于 2016-9-2 20:33:34 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. !include LogicLib.nsh

  2. !define AF_INET         2
  3. !define SOCK_STREAM     1
  4. !define IPPROTO_TCP     6

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

  11. ;Create a SOCKET for listening for incoming connection requests
  12. System::Call Ws2_32::socket(i${AF_INET},i${SOCK_STREAM},i${IPPROTO_TCP})i.r1
  13. StrCmp $1 0 Cleanup
  14. System::Call Ws2_32::inet_addr(t"127.0.0.1")i.s
  15. System::Call Ws2_32::htons(i80)i.s
  16. System::Call "*(&i2 ${AF_INET}, &i2 s, i s, &t8) i.r2"
  17. ;Bind the socket.
  18. System::Call Ws2_32::bind(ir1,ir2,i16)i.r3
  19. ${If} $3 = -1
  20. MessageBox MB_ICONINFORMATION|MB_OK "bind() failed."
  21. System::Call Ws2_32::WSAGetLastError()i.r3
  22.   ${If} $3 = 10048
  23.     MessageBox MB_ICONINFORMATION|MB_OK "80端口被占用"
  24.   ${EndIf}
  25. ${EndIf}
  26. System::Call Ws2_32::closesocket(ir1)
  27. System::Free $2
  28. Cleanup:
  29. System::Call Ws2_32::WSACleanup()
  30. done:
  31. System::Free $0
  32. SectionEnd
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 19:32 , Processed in 0.116339 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表