【C#】简单二维码制作和打印

article/2025/8/26 6:11:40

系列文章

【C#】条码管理操作手册
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126589496

【C#】IIS平台下,WebAPI发布及异常处理
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126539836

【C#】简单二维码制作和打印
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126884228

【C#】最全单据打印源码(打印模板、条形码&二维码、字体样式)
本文链接:https://blog.csdn.net/youcheng_ge/article/details/129415723


文章目录

  • 系列文章
  • 前言
  • 一、问题描述
  • 二、解决方案
    • 2.1 需求分析
    • 2.2 实施方案
  • 三、软件开发(源码展示)
    • 3.1 引入组件
    • 3.2 二维码图片绘制方法
    • 3.3 二维码图片调用(样例1)
    • 3.3 标签制作源码(核心)
    • 3.5 批量生成二维码
    • 3.6 底层库richTextBox打印类
    • 3.7 richTextBox打印的调用
      • 3.7.1 预览
      • 3.7.2 打印
  • 四、程序运行效果
  • 五、资源链接


前言

我能抽象出整个世界,但是我不能抽象你。 想让你成为私有常量,这样外部函数就无法访问你。 又想让你成为全局常量,这样在我的整个生命周期都可以调用你。 可惜世上没有这样的常量,我也无法定义你,因为你在我心中是那么的具体。

哈喽大家好,本专栏为【项目实战】专栏,有别于【底层库】专栏,本专栏介绍项目开发过程中,遇到问题的解决方案,是我实际项目开发过程,相对成熟、可靠方法的提炼,我将这些问题的处理思路梳理,撰写本文分享给大家,大家遇到类似问题,可按本文方案处理。

本专栏会持续更新,不断完善,大家有任何问题,可以私信我。本专栏之间关联性较弱(文章之间依赖性较弱,没有阅读顺序区分)。如果您对本专栏感兴趣,欢迎关注吧,我将带你用最简洁的代码,实现最复杂的功能。

·提示:本专栏为项目实战篇,未接触项目开发的同学可能理解困难,不推荐阅读。

一、问题描述

我入职的公司性质为生产型公司,对于原材料,有多家供应商供应,质量也就参差不齐,所以需要先检验,再入库。

目前,来料由物理实验室批量检测,再由部门文员,维护Excel表格,最后再将表格表格上传内部共享盘,此方法效率低、成本高、数据容易录错,且不满足日益增长的数据需要,尤其对于黄丝编号、AVE直径、AVE拉力、强度值(计算值)等录入容易出错。

于是,我设计了条码管理的方案:将来料编号生成二维码(打标),张贴在货物上(贴标),后道部门扫码获取物料信息(读标)。员工们只需拿一台手持机,即可完成一系列复杂的操作。

在这里插入图片描述
提示:手持机它长这样子,可以理解为你淘汰的智能手机+键盘,某些科技企业已升级到工业pad,屏幕更大、性能更强。


二、解决方案

2.1 需求分析

与业务部门沟通,进一步确定标签需要支持以下目标:
①公司存在保密要求,标签不便显示产品信息,但特定人员可以看懂。
②编号要可以人工复核,双重保障,防止识别不出可以人工干预。

其实描述一大堆,你只需要在原有二维码的基础上增加文字信息,便于人工查看。那么如何制作【二维码标签】呢,说白了就是:对原生成的二维码进行重绘,增加文字信息,效果如下图:

说白了就是,需要对原生成的二维码进行重绘,重新增加文字信息,效果如下图:
提示:这个编号是公司内部定的,特有定含义,并不是单纯的随机码、也不是流水号,就是说有份【数据字典】可以查询标签信息。这个我们就不用深究了,我做了标签识别功能,专门解析这个玩意。

标签识别效果:
在这里插入图片描述
PS:补充一句,我标签采用图片绘制的方式,这不是通用的产品,我原本计划产品通用化,将做成模板,【二维码】制作成条码控件,标签信息制作成文本控件,支持颜色、位置、数值计算、控件拖拽调整,模板保存成xml文件,支持拷贝修改。但是时间有限,只完成了原型构建,后期有时间将改造这部分。

2.2 实施方案

二维码生成很简单,使用QRCodeEncoder可以生成一个【二维码】,但是它生成的仅仅是个【二维码】,没有文字信息记录,不符合我们的需要。

其实吧,有了【二维码】让客户放文档编辑编辑,二次加工也能符合他需求。但是吧,作为软件设计师宗旨:就是解决问题,让客户操作更便捷,能节省的步骤尽可能帮其他省略。

我的方案:

①生成【二维码】图片

②画一个白底的图片,要比【二维码】图片大一些

③把【二维码】图片放上去,底部留白的地方在加上文字说明。

编程需要用到的类:

使用 GDI+ 画图会用到的几个常用的类有:Graphics、Bitmap、Image。
其中 Graphics 是画板。这个类包含了许多画图的方法,包括画图片(DrawImage),画线(DrawLine),画圆(DrawEllipse、FillEllipse),写字(DrawString)等等。简单说使用这个类可以完成我们需要的大部分工作。

三、软件开发(源码展示)

3.1 引入组件

安装QRCode组件,它支持一维码(条形码)、二维码生成。NuGet搜索一下,直接安装完事儿了。如果是离线状态下,你将ThoughtWorks.QRCode.dll组件,直接import进去好了。

在这里插入图片描述

3.2 二维码图片绘制方法

我这里进行封装,传入参数标签编号,获得Bitmap对象。Bitmap对象可以用于富文本的展示。

        private Bitmap DrawImage(string a_strLabel){Thread.Sleep(500);string l_strMode = AppConfig.GetValue("qr_mode");string l_strSize = AppConfig.GetValue("qr_size");string l_strVersion = AppConfig.GetValue("qr_version");string l_strCheckLevel = AppConfig.GetValue("qr_checklevel");QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();// 生成二维码内容模式分为三种,数字,数字字母,字节,这个基本上都设置成Byte,支持汉字qrCodeEncoder.QRCodeEncodeMode = (QRCodeEncoder.ENCODE_MODE)Enum.Parse(typeof(QRCodeEncoder.ENCODE_MODE), l_strMode);// 设置二维码的大小,默认4,在尺寸小的情况下,版本参数过高则设备难以识别二维码qrCodeEncoder.QRCodeScale = int.Parse(l_strSize);// 设置二维码的版本,默认7 该值影响二维码最高数据容量 7大致对应40个汉字长度,内容超出择需提升该数值qrCodeEncoder.QRCodeVersion = int.Parse(l_strVersion);// 设置错误校验级别,默认中等,二维码被遮挡住一部分实际上也是能扫出内容的,这个效验级别的意思就是// 当遮挡部分最大占整体多少时仍然可以被扫出来,M大概在20%左右,H为30%,级别越高相应的数据容量会缩小// 那些中间带图标的二维码,其实就是简单粗暴的用LOGO遮挡住了中间部分qrCodeEncoder.QRCodeErrorCorrect = (QRCodeEncoder.ERROR_CORRECTION)Enum.Parse(typeof(QRCodeEncoder.ERROR_CORRECTION), l_strCheckLevel);return qrCodeEncoder.Encode(a_strLabel, Encoding.UTF8);}

3.3 二维码图片调用(样例1)

行改变调用,我这里做成选择那一行编号,它就可以预览标签,支持一键打印的。

 private void GV_Main_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e){Bitmap image = null;int l_intFontSize = Convert.ToInt32(AppConfig.GetValue("qr_fontsize"));if (GV_Main.FocusedRowHandle > -1){string l_strLabel = GV_Main.GetFocusedDataRow()["code_no"].ToString();if (!string.IsNullOrWhiteSpace(l_strLabel)){image = DrawImage(l_strLabel);richTextBox2.Clear();richTextBox2.BackColor = Color.White;richTextBox2.ForeColor = Color.Blue;richTextBox2.SelectionColor = Color.White;richTextBox2.Font = new Font("黑体", l_intFontSize);richTextBox2.SelectionStart = richTextBox2.Text.Length;Clipboard.SetDataObject(image, false);//将图片放在剪贴板中DataFormats.Format dataFormat = DataFormats.GetFormat(DataFormats.Bitmap);//将剪贴板中的内容贴入RichTextBox中if (richTextBox2.CanPaste(dataFormat))richTextBox2.Paste(dataFormat);richTextBox2.AppendText(Environment.NewLine + "编号:" + l_strLabel);image.Dispose();Clipboard.Clear();//一定要清空剪切板,否则会报错string str = "0";//指定字符串int index = -1;while ((index = richTextBox2.Find(str, index + 1, RichTextBoxFinds.MatchCase)) != -1){richTextBox2.Select(index, 1);//选中这个段落richTextBox2.SelectionFont = new Font("黑体", l_intFontSize, FontStyle.Underline);//设置字体名称为“黑体”,字号为14号,字体样式为加粗if (index + 1 == richTextBox2.Text.Length){break;}}}}else{richTextBox2.Text = "";}}

3.3 标签制作源码(核心)

本文的核心内容,就是如何写标签,生成图片类,
传入参数:标签编号、文件路径。
AppConfig.GetValue()为读取配置文件中的参数信息,就是标签的宽度、高度、二维码的宽度、高度、二维码的坐标等。

private void CreatePicture(string a_strCodeNo,string a_strFilePath){int l_intImgWidth = Convert.ToInt32(AppConfig.GetValue("img_width"));int l_intImgHeight = Convert.ToInt32(AppConfig.GetValue("img_height"));int l_intCodeWidth = Convert.ToInt32(AppConfig.GetValue("code_width"));int l_intCodeHeight = Convert.ToInt32(AppConfig.GetValue("code_height"));int l_intCodeX = Convert.ToInt32(AppConfig.GetValue("code_x"));int l_intCodeY = Convert.ToInt32(AppConfig.GetValue("code_y"));int l_intFontSize = Convert.ToInt32(AppConfig.GetValue("qr_fontsize"));int l_intFontX = Convert.ToInt32(AppConfig.GetValue("font_x"));int l_intFontY = Convert.ToInt32(AppConfig.GetValue("font_y"));Image image = null;Bitmap imagedata = new Bitmap(l_intImgWidth, l_intImgHeight); //创建画布150*150。Graphics g = null;try{g = Graphics.FromImage(imagedata);//绘制Rectangle c = new Rectangle(0, 0, l_intImgWidth, l_intImgHeight);//矩形框g.FillRectangle(Brushes.White, c);//白色底色填充画布image = DrawImage(a_strCodeNo); //获取二维码的 Bitmap,由于Image是Bitmap的父类自动转换g.DrawImage(image, l_intCodeX, l_intCodeY, l_intCodeWidth, l_intCodeHeight);//绘制二维码到画布,留边距20像素g.DrawString($"编号:{a_strCodeNo}", new Font("黑体", l_intFontSize, FontStyle.Regular),new SolidBrush(Color.Black), l_intFontX, l_intFontY);                   //绘制文字imagedata.Save(a_strFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存图片}catch (System.Exception ex){throw ex;}finally{g.Dispose();imagedata.Dispose();image.Dispose();}}

3.5 批量生成二维码

按钮事件,点击批量生成一堆标签。

 //批量下载private void Mi_BatchSave_Click(object sender, EventArgs e){DataTable l_dt = GC_Main.DataSource as DataTable;if (l_dt == null || l_dt.Rows.Count == 0){return;}FolderBrowserDialog dialog = new FolderBrowserDialog();dialog.Description = "请选择路径";dialog.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;if (dialog.ShowDialog() == DialogResult.OK){string l_strDir = dialog.SelectedPath;foreach (DataRow dr in l_dt.Rows){string l_strCodeNo = dr["code_no"].ToString();string l_strFilePath = Path.Combine(l_strDir, l_strCodeNo + ".jpg");CreatePicture(l_strCodeNo, l_strFilePath);}FrmTips.ShowTipsSuccess(this, "保存成功!");System.Diagnostics.Process.Start(l_strDir);}}

3.6 底层库richTextBox打印类

《底层库–richTextBox打印类》,创建类文件 richTextBoxPrintClass.cs,复制以下代码:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Drawing.Printing;namespace QRCodeProduce
{public class richTextBoxPrintClass{public richTextBoxPrintClass(){InitializeComponent();}#region 打印功用//and the unit used by Win32 API calls (twips 1/1440 inch)private const double anInch = 14.4;[StructLayout(LayoutKind.Sequential)]private struct RECT{public int Left;public int Top;public int Right;public int Bottom;}[StructLayout(LayoutKind.Sequential)]private struct CHARRANGE{public int cpMin;         //First character of range (0 for start of doc)public int cpMax;           //Last character of range (-1 for end of doc)}[StructLayout(LayoutKind.Sequential)]private struct FORMATRANGE{public IntPtr hdc;             //Actual DC to draw onpublic IntPtr hdcTarget;       //Target DC for determining text formattingpublic RECT rc;                //Region of the DC to draw to (in twips)public RECT rcPage;            //Region of the whole DC (page size) (in twips)public CHARRANGE chrg;         //Range of text to draw (see earlier declaration)}private const int WM_USER = 0x0400;private const int EM_FORMATRANGE = WM_USER + 57;[DllImport("USER32.dll")]private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);// Render the contents of the RichTextBox for printing//	Return the last character printed + 1 (printing start from this point for next page)public static int Print(RichTextBox richTextBox, int charFrom, int charTo, PrintPageEventArgs e){//Calculate the area to render and printRECT rectToPrint;rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);//Calculate the size of the pageRECT rectPage;rectPage.Top = (int)(e.PageBounds.Top * anInch);rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);rectPage.Left = (int)(e.PageBounds.Left * anInch);rectPage.Right = (int)(e.PageBounds.Right * anInch);IntPtr hdc = e.Graphics.GetHdc();FORMATRANGE fmtRange;fmtRange.chrg.cpMax = charTo;				//Indicate character from to character to fmtRange.chrg.cpMin = charFrom;fmtRange.hdc = hdc;                    //Use the same DC for measuring and renderingfmtRange.hdcTarget = hdc;              //Point at printer hDCfmtRange.rc = rectToPrint;             //Indicate the area on page to printfmtRange.rcPage = rectPage;            //Indicate size of pageIntPtr res = IntPtr.Zero;IntPtr wparam = IntPtr.Zero;wparam = new IntPtr(1);//Get the pointer to the FORMATRANGE structure in memoryIntPtr lparam = IntPtr.Zero;lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));Marshal.StructureToPtr(fmtRange, lparam, false);//Send the rendered data for printing res = SendMessage(richTextBox.Handle, EM_FORMATRANGE, wparam, lparam);//Free the block of memory allocatedMarshal.FreeCoTaskMem(lparam);//Release the device context handle obtained by a previous calle.Graphics.ReleaseHdc(hdc);//Return last + 1 character printerreturn res.ToInt32();}#endregion#region 初始化public RichTextBox richTextBox;private PageSetupDialog pageSetupDialog1;private PrintDialog printDialog1;private PrintDocument printDocument1;private PrintPreviewDialog printPreviewDialog1;private void InitializeComponent(){richTextBox = new RichTextBox();pageSetupDialog1 = new PageSetupDialog();printDialog1 = new PrintDialog();printDocument1 = new PrintDocument();printPreviewDialog1 = new PrintPreviewDialog();//尺寸大小(标签打印机尺寸,数值调大)//PaperSize size1 = new PaperSize("自定", 300, 130);PaperSize size1 = new PaperSize("自定", 350, 150);printDocument1.DefaultPageSettings.PaperSize = size1;//object aa = printDocument1.DefaultPageSettings.Margins;printDocument1.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(100, 100, 15, 5);//printDocument1.DefaultPageSettings.Landscape = true;(不能加)// // pageSetupDialog1// pageSetupDialog1.Document = printDocument1;// // printDialog1// printDialog1.Document = printDocument1;printDialog1.UseEXDialog = true;// // printDocument1// printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument1_BeginPrint);// // printPreviewDialog1// printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);printPreviewDialog1.ClientSize = new System.Drawing.Size(1800, 1200);printPreviewDialog1.Document = printDocument1;printPreviewDialog1.Enabled = true;// printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));printPreviewDialog1.Name = "printPreviewDialog1";printPreviewDialog1.Visible = false;}private int checkPrint;private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e){checkPrint = 0;}private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e){// Print the content of RichTextBox. Store the last character printed.//checkPrint = richTextBoxPrintCtrl1.Print(checkPrint, richTextBoxPrintCtrl1.TextLength, e);checkPrint = richTextBoxPrintClass.Print(richTextBox, checkPrint, richTextBox.TextLength, e);// Check for more pagesif (checkPrint < richTextBox.TextLength)e.HasMorePages = true;elsee.HasMorePages = false;}#endregion//打印设置public void ShowPrintDialog(){printDialog1.ShowDialog();}//页面设置功能public void ShowPageSetupDlg(){pageSetupDialog1.ShowDialog();}//打印预览功能public void ShowShowPagePriviewDlg(){printPreviewDialog1.ShowDialog();}//打印public void ShowPrintDlg(){if (printDialog1.ShowDialog() == DialogResult.OK)printDocument1.Print();}}
}

3.7 richTextBox打印的调用

3.7.1 预览

        /// <summary>/// 打印预览/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void BTN_PrintPreview_Click(object sender, EventArgs e){richTextBoxPrintClass r = new richTextBoxPrintClass();r.richTextBox = richTextBox2;r.ShowShowPagePriviewDlg();}

在这里插入图片描述

3.7.2 打印

        /// <summary>/// 打印/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void BTN_Print_Click(object sender, EventArgs e){richTextBoxPrintClass r = new richTextBoxPrintClass();r.richTextBox = richTextBox2;r.ShowPrintDlg();}

四、程序运行效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

五、资源链接

项目源码 QRCodeProduce
链接:https://pan.baidu.com/s/1b1V3ge6EgYWkxEo2hQwAiA?pwd=9y2j
提取码:9y2j

本文为早期创作,标签设计具有局限性。大家阅读下面这篇文章,下文更加完美。
【C#】最全单据打印源码(打印模板、条形码&二维码、字体样式)
本文链接:https://blog.csdn.net/youcheng_ge/article/details/129415723


http://chatgpt.dhexx.cn/article/TGGIfLIV.shtml

相关文章

一维码二维码的生成及打印

VUE条形码及二维码的生成及输出到打印机 文章目录 VUE条形码及二维码的生成及输出到打印机1. 条形码的生成2. 二维码的生成3. 输出打印4. 将代码提取一下 1. 条形码的生成 安装插件 npm install jsbarcode --save github地址&#xff1a; https://github.com/lindell/JsBarcode…

C#二维码的生成及打印

窗体设计显示图 一&#xff0c;生成二维码 /// <summary>/// 生成二维码/// </summary>/// <param name"text">内容</param>/// <param name"width">宽度</param>/// <param name"height">高度</p…

生成二维码,并且打印

生成二维码&#xff0c;并且打印出来 加入依赖 //二维码依赖 npm install --save qrcodejs2 //打印依赖 npm install vue-print-nb --save在mian文件夹中使用引入并使用&#xff0c;或者按需引入 //打印依赖 import Print from vue-print-nb Vue.use(Print)本次二维码是按需引…

二维码打印

1. 二维码简介 二维码&#xff08;2-dimensional bar code&#xff09;&#xff0c;又称二维条码&#xff0c;它是用特定的几何图形按一定规律在平面&#xff08;二维方向&#xff09;上分布的黑白相间的图形&#xff0c;是所有信息数据的一把钥匙。在现代商业活动中&…

vue生成条形码和二维码并打印

文章目录 前言一、生成条形码二、生成二维码三、效果图四、打印 前言 最近有一个需求&#xff0c;需要将产品信息生成标签&#xff0c;每个信息生成一个条形码&#xff0c;拿到所有数据生成二维码&#xff0c;最后打印标签。 一、生成条形码 使用jsbarcode&#xff0c;直接in…

vue二维码生成、打印及识别

生成二维码 引入QRCode模块 npm install --save qrcode import QRCode from qrcode; 页面代码 批量创建二维码及打印&#xff0c;所以加了个v-for <div id"printDiv"/**后面打印用到的区域id*/ :disabled"hussar_20Disabled" ref"hussar_20Ref&quo…

如何将内网ip映射到外网

这个百度经验上就有&#xff0c;不过对于着急使用的我来说&#xff0c;差了最后一步。所以还是一起记上吧。 第一步 首先登陆你的路由器&#xff0c;就改密码那个。一般就用浏览器直接打开192.168.1.1就可以&#xff0c;账号密码有可能是 admin admin吧&#xff0c;默认可能是…

VMWare虚拟机局域网网络配置,主机访问虚拟机上的网站(端口映射)

文章目录 1 problem2 背景知识3 配置主机网络4 配置虚拟机网络 1 problem 如题&#xff0c;现在虚拟机的80端口和8080端口都有一个网站&#xff0c;我们想要在主机访问它。 2 背景知识 VmWare支持3种网络连接模式。 1、桥接模式&#xff1a; 所谓桥接就是把两个本来分开…

映射公网的几种方式

转载自&#xff1a;http://blog.csdn.net/sadshen/article/details/48240519 这篇文章花了好几天&#xff0c;系统地梳理出了映射公网的几种方式。虽然是针对微信开发的外网服务器来寻找解决方案&#xff0c;但这个知识梳理可能会在其他地方也受益。平常我也有用TeamViewer&…

VMware NAT端口映射 外网可以访问内网虚拟机

我想尝试的是利用本机的ipport来访问虚拟机上的web服务器&#xff0c;因为这样的话&#xff0c;我就能够将我的web服务器部署成为一个能让外网访问的服务器了&#xff0c;首先说下我的环境&#xff1a; 主机&#xff1a;系统win7&#xff0c;ip地址172.18.186.210 虚拟机版本是…

如何把内网IP映射到公网IP

鸽子出品 2017-12-05 22:28:22 我们讲了如何搭建网站&#xff0c;可是有很多小伙伴私信跟我说怎么映射&#xff0c;今天我就教大家如何把内网地址映射到公网&#xff01; 我们所需要的工具有&#xff1a; 内网IP&#xff08;这个是品&#xff0c;也是必有的&#xff01;&…

简单内网映射到公网方法--免费

我是一名Android API Player&#xff0c;最近公司需要做微信公众号二次开发&#xff0c;我跟着学学&#xff0c;公司后台.net。 我mac安装windows之后用vs感觉太差了&#xff0c;可能是我的mac要淘汰了吧。 所以我决定用java后台来跟着做。 仔细一想我没有服务器啊。 再仔细…

本地主机搭建服务器后如何让外网访问?快解析内网端口映射

本地主机搭建应用、部署服务器后&#xff0c;在局域网内是可以直接通过计算机内网IP网络地址进行连接访问的&#xff0c;但在外网电脑和设备如何访问呢&#xff1f;由于内网环境下&#xff0c;无法提供公网IP使用&#xff0c;外网访问内网就需要一个内外网转换的介质。这里介绍…

内网和外网之间的通信(端口映射原理)

内网和外网之间的通信&#xff08;端口映射原理&#xff09; 首先解释一下“内网”与“外网”的概念&#xff1a; 内网&#xff1a;即所说的局域网&#xff0c;比如学校的局域网&#xff0c;局域网内每台计算机的IP地址在本局域网内具有互异性&#xff0c;是不可重复的。但两…

实现内网通过外网域名访问NAT映射的内网服务器

大家都知道在用Huawei的中低端路由器做NAT地址映射时只能支持 “外网访问” 不支持 “内网访问”。也就是说只支持NAT映射后外网IP通过外网域名&#xff08;外网IP&#xff09;访问NAT映射的服务器 &#xff0c;不支持NAT映射后内网IP通过外网域名&#xff08;外网IP&#xff0…

给内网映射增加安全防护

1.背景 内部网络资源的访问&#xff0c;通用的做法是部署企业VPN&#xff0c;通过VPN设备提供公网接入服务&#xff0c;客户端接入后&#xff0c;则可以像本地网络一样访问内网资源。但是部署VPN需要专业设备&#xff0c;且配置管理往往需要专业人员&#xff0c;对普通小…

公网映射思路

1、使用环境 目前政务微信的有两台内网环境71和14服务器&#xff0c;外网不能访问&#xff0c;只能内部访问&#xff0c;但是项目部署在14上面71的nginx转发到14服务器上面&#xff0c;但是现在14的项目需要网络支持&#xff0c;另外需要一台公网环境180服务器。 2、公网环境…

外网做ip映射访问内网链接

首先这个外网必须是独立ip 然后在路由器设置ip映射&#xff0c;注意防火墙放通该端口&#xff0c;可以telnet连一下试试有没通

几种内网映射到公网的方法

1、windows_386_ngork ngrok.exe用来将内网映射到外网上&#xff0c;即让外网能访问局域网内本地的应用&#xff0c;例如在外网访问你本地http://127.0.0.1指向的Web站点。下载windows_386_ngork软件&#xff0c;可以到官网下载&#xff0c;可以直接用我提供的下载地址&#x…

云服务器部署内网穿透映射本地服务

项目开发时需要和前端联调&#xff0c;考虑使用内网穿透避免每次上传服务部署的过程 下载frp &#xff08;开源内网穿透、反向代理工具&#xff09; https://github.com/fatedier/frp/releases/上传云服务器并解压&#xff08;使用xftp等工具上传&#xff09; tar -zxvf frp_0…