中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-17 13:22
47,812 topics / 349,917 posts / today 0 new / 48,270 members
DOS批处理 & 脚本技术(批处理室) » [Help] IP type conversion problem: how to convert dotted-decimal IP to numeric type
Printable Version  1,432 / 7
Floor1 gotocmd Posted 2009-01-16 14:10
新手上路 Posts 20 Credits 19
The problem of converting numeric type to decimal IP has already been solved here:
http://cn-dos.net/forum/viewthread.php?tid=45528&fpage=1

But the other way around, how do you convert decimal IP to numeric IP?

───────────────── Moderator Log ─────────────────
Handled by: HAT
Action: added search keywords to the post title
Note: the original title "ip type conversion problem" was not good for forum searching
Penalty: new forum users are exempt from credits penalties
Tip: it is recommended to read the following posts
{1415}The Wisdom of Asking Questions
{7326}Forum newbie must-read, the basic code of conduct for everyone
{22703}Please don't be an impetuous person
{32667} Those people who can't even write a clear title, wake up
{32825}This section is strictly cleaning up bad posts
───────────────── Moderator Log ─────────────────


[ Last edited by HAT on 2009-1-16 at 15:39 ]
Floor2 slore Posted 2009-01-16 14:36
铂金会员 Posts 2,478 Credits 5,212
Floor3 slore Posted 2009-01-16 14:39
铂金会员 Posts 2,478 Credits 5,212
I don't know whether CMD has any simple way for the numeric range.

Below is a VBS one:
IP = "223.255.255.255"
dip = Split(IP,".")
outip = dip(0) * 256 * 256 * 256
outip = outip + dip(1) * 256 * 256
outip = outip + dip(2) * 256
outip = outip + dip(3)
MsgBox outip
Floor4 gotocmd Posted 2009-01-16 15:11
新手上路 Posts 20 Credits 19
Thanks, brother slore. This only converts a single IP; it's my fault for not making it clear.
It's like this: through "ShowIp.exe" (a tool for the Chunzhen IP database) I get the text file ip.txt, with content in the following format:
0.0.0.0 0.255.255.255 IANA CZ88.NET
1.0.0.0 1.51.255.255 IANA CZ88.NET
1.52.0.0 1.52.255.255 United States CZ88.NET
1.53.0.0 1.153.255.255 IANA CZ88.NET
1.154.0.0 1.154.255.255 United States CZ88.NET
1.155.0.0 1.255.255.255 IANA CZ88.NET
2.0.0.0 2.255.255.255 IANA CZ88.NET
3.0.0.0 3.255.255.255 United States General Electric Company, New Jersey
4.0.0.0 4.9.255.255 United States CZ88.NET
4.10.0.0 4.10.255.255 United States New Jersey State University
......

How can I get file ip_out.txt with content in the format:
0 16777215 IANA CZ88.NET
16777216 33554431 IANA CZ88.NET
33554432 50331647 United States CZ88.NET
........
Floor5 gotocmd Posted 2009-01-17 12:54
新手上路 Posts 20 Credits 19
Bumping this myself
Waiting for an expert to solve it....
Floor6 netbenton Posted 2009-01-20 14:43
银牌会员 Posts 752 Credits 1,916 From 广西
Floor7 slore Posted 2009-01-20 14:51
铂金会员 Posts 2,478 Credits 5,212
=.=

Sure enough, after 128 it gets very troublesome~
Floor8 netbenton Posted 2009-01-21 14:02
银牌会员 Posts 752 Credits 1,916 From 广西
Improved the formatting, and simplified the code

@echo off&setlocal enabledelayedexpansion
for /f "tokens=1-8,* delims= . " %%a in ('type ip.txt') do (
Call :GetDIP %%a %%b %%c %%d one
Call :GetDIP %%e %%f %%g %%h tow
if "!one:~4,1!"=="" set/p "= "<nul
echo !one! !tow! %%i
)
pause
goto :eof

:GetDIP
set /a sur=%2*256*256+%3*256+%4

if %1 gtr 127 (
set /a "sur=(%1-128)*256*256*256+!sur!"
set suw=000000000!sur:~-9!
set /a suw=1!suw:~-9!-1000000000+147483648
set /a sut=!sur:~0,-9!+!suw:~0,-9!+2
set "sur=!sut!!suw:~-9!"
) else (
set /a sur=%1*256*256*256+!sur!
)

set "%5=!sur!"
goto :eof
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023