China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 15:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] IP type conversion problem: how to convert dotted-decimal IP to numeric type View 1,293 Replies 7
Original Poster Posted 2009-01-16 14:10 ·  中国 广东 韶关 电信
新手上路
Credits 19
Posts 20
Joined 2008-07-03 20:33
18-year member
UID 121064
Gender Male
Status Offline
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 ]
Floor 2 Posted 2009-01-16 14:36 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 3 Posted 2009-01-16 14:39 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 4 Posted 2009-01-16 15:11 ·  中国 广东 韶关 电信
新手上路
Credits 19
Posts 20
Joined 2008-07-03 20:33
18-year member
UID 121064
Gender Male
Status Offline
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
........
Floor 5 Posted 2009-01-17 12:54 ·  中国 广东 韶关 电信
新手上路
Credits 19
Posts 20
Joined 2008-07-03 20:33
18-year member
UID 121064
Gender Male
Status Offline
Bumping this myself
Waiting for an expert to solve it....
Floor 6 Posted 2009-01-20 14:43 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
精简
=> 个人网志
Floor 7 Posted 2009-01-20 14:51 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
=.=

Sure enough, after 128 it gets very troublesome~
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 8 Posted 2009-01-21 14:02 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
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
精简
=> 个人网志
Forum Jump: